NO

Author Topic: Code, setting, or other that only includes include files that are used  (Read 782 times)

Offline alderman2

  • Member
  • *
  • Posts: 60
    • Xmag
As overhead, is there any way to exclude included files that are included but not used?

Example:
When I include my entire library
       
Code: [Select]
#include "../_ASSETC_/_ac.hWill be the exe file of 155kb

When I only include what is needed
   
Code: [Select]
// Include required files if one and one are included below
#include "../_ASSETC_/_ac_define.h"
#include "../_ASSETC_/ac_WindowMain_1.h"
#include "../_ASSETC_/ac_WindowMainGetArgument_1.h"
// Include what is needed
#include "../_ASSETC_/ac_WindowCreate_1.h"
#include "../_ASSETC_/ac_WindowSetCenterPos_1.h"
#include "../_ASSETC_/ac_WindowSetResIcon_1.h"
#include "../_ASSETC_/ac_GraphicCreateTextFont_1.h"
#include "../_ASSETC_/ac_ButtonSimpleCreate_1.h"
#include "../_ASSETC_/ac_GraphicSetTextOut_1.h"
Will the exe file be 27kB

I would prefer to include the entire library before it goes much faster. Out of about 800 included files, I may only use a few. The rest becomes junk code in the exe file. Is there a way to exclude the unused files when I include the entire library?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2151
Re: Code, setting, or other that only includes include files that are used
« Reply #1 on: December 17, 2024, 11:25:21 AM »
if code is in c-files, have to split functions to own files.
with include files some conditionals may help.

pocc don't support COMDATs.


EDIT:
split source file using tags
was for having one file for editing and for compilers, that supports COMDAT and easy way to split code for pocc
« Last Edit: December 17, 2024, 12:36:11 PM by TimoVJL »
May the source be with you

Offline alderman2

  • Member
  • *
  • Posts: 60
    • Xmag
Re: Code, setting, or other that only includes include files that are used
« Reply #2 on: December 17, 2024, 11:52:26 AM »
OK!
I have to put them in manually after I finish my code.

Offline John Z

  • Member
  • *
  • Posts: 920
Re: Code, setting, or other that only includes include files that are used
« Reply #3 on: December 17, 2024, 12:17:21 PM »
Hi Alderman2,

Yup, there is a long discussion thread somewhere in here educating me on the benefits of one file per function as the best method for both maintenance, and minimizing bloat due to unused code.

I think the next best alternative was to build libraries, then the function is only pulled in if used.

John Z

Offline alderman2

  • Member
  • *
  • Posts: 60
    • Xmag
Re: Code, setting, or other that only includes include files that are used
« Reply #4 on: December 17, 2024, 04:02:29 PM »
OK!
I was lazy for not looking for that thread first. I continue as before. First, I build the program with the entire "library" included. When I'm done, I look up the features needed and include them. Been doing that for a 20-25 years so it's no problem.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2151
Re: Code, setting, or other that only includes include files that are used
« Reply #5 on: December 17, 2024, 04:30:28 PM »
Map file can be useful to find out used object files
« Last Edit: December 17, 2024, 04:32:03 PM by TimoVJL »
May the source be with you

Offline alderman2

  • Member
  • *
  • Posts: 60
    • Xmag
Re: Code, setting, or other that only includes include files that are used
« Reply #6 on: December 17, 2024, 06:22:45 PM »
Good idea!
Why didn't I think of that before?

Offline John Z

  • Member
  • *
  • Posts: 920
Re: Code, setting, or other that only includes include files that are used
« Reply #7 on: December 17, 2024, 08:27:21 PM »
There is also an add-in Line Counter + that can tell you unused procedures and how many times each procedure is called, plus other information.

Accuracy is some what dependent on the coding style, so maybe not always 100% .

John Z

Offline alderman2

  • Member
  • *
  • Posts: 60
    • Xmag
Re: Code, setting, or other that only includes include files that are used
« Reply #8 on: December 17, 2024, 11:35:16 PM »
OK!
May be useful.
Since I'm not quite 100 with my programming, I don't expect anyone else to be either.  ;)

Offline John Z

  • Member
  • *
  • Posts: 920
Re: Code, setting, or other that only includes include files that are used
« Reply #9 on: December 17, 2024, 11:50:11 PM »
 :)

I probably should rewrite part of it to use the Pelle tree view data instead of my own parsing of what is a procedure.  But it is fairly good …..

John Z

Offline alderman2

  • Member
  • *
  • Posts: 60
    • Xmag
Re: Code, setting, or other that only includes include files that are used
« Reply #10 on: December 18, 2024, 05:43:56 AM »
I can just uncheck the main include file and compile. Then I get an error list of what should be included.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2151
Re: Code, setting, or other that only includes include files that are used
« Reply #11 on: December 18, 2024, 01:10:29 PM »
that gives only function names.
with static library, map-file gives also module names.
processing include files are not easy with conditional defines.
May the source be with you

Offline alderman2

  • Member
  • *
  • Posts: 60
    • Xmag
Re: Code, setting, or other that only includes include files that are used
« Reply #12 on: December 18, 2024, 08:10:22 PM »
Glad you said that!
I'll look into it next time I work with Pelles.

Offline HellOfMice

  • Member
  • *
  • Posts: 203
  • Never be pleased, always improve
Re: Code, setting, or other that only includes include files that are used
« Reply #13 on: December 19, 2024, 01:28:20 PM »
Hello,

With some include files it is like you read a book very difficult to understand.

I make one per subject / function

If I make something wrong I don't damaged the whole source file.

It is easier to understand too

Where is you line counter add-in, John?

Philippe

PS: I'm ashamed, I messed up on our last program!
--------------------------------
Kenavo

Offline John Z

  • Member
  • *
  • Posts: 920
Re: Code, setting, or other that only includes include files that are used
« Reply #14 on: December 19, 2024, 04:14:14 PM »
Hi HellOfMice,

Don't beat yourself up so much.  The tool works, just the scope is limited to Pelles C .rc files, which does not make it failure, just a dedicated tool.

Line counter + is at
https://forum.pellesc.de/index.php?topic=10092.75
Haven't looked at it for awhile might be time to improve it.  In a few short years it has risen to the most ever viewed Add-in thread  :)

John Z