Code, setting, or other that only includes include files that are used

Started by alderman2, December 17, 2024, 10:35:48 AM

Previous topic - Next topic

alderman2

As overhead, is there any way to exclude included files that are included but not used?

Example:
When I include my entire library
        #include "../_ASSETC_/_ac.h
Will be the exe file of 155kb

When I only include what is needed
   // 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?

TimoVJL

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
May the source be with you

alderman2


John Z

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

alderman2

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.

TimoVJL

Map file can be useful to find out used object files
May the source be with you

alderman2


John Z

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

alderman2

OK!
May be useful.
Since I'm not quite 100 with my programming, I don't expect anyone else to be either.  ;)

John Z

 :)

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

alderman2

I can just uncheck the main include file and compile. Then I get an error list of what should be included.

TimoVJL

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

alderman2

Glad you said that!
I'll look into it next time I work with Pelles.

HellOfMice

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!

John Z

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