Pelles C forum

Pelles C => General discussions => Topic started by: alderman2 on December 17, 2024, 10:35:48 AM

Title: Code, setting, or other that only includes include files that are used
Post by: alderman2 on December 17, 2024, 10:35:48 AM
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?
Title: Re: Code, setting, or other that only includes include files that are used
Post by: TimoVJL 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 (https://forum.pellesc.de/index.php?topic=7387.msg28079#msg28079)
was for having one file for editing and for compilers, that supports COMDAT and easy way to split code for pocc
Title: Re: Code, setting, or other that only includes include files that are used
Post by: alderman2 on December 17, 2024, 11:52:26 AM
OK!
I have to put them in manually after I finish my code.
Title: Re: Code, setting, or other that only includes include files that are used
Post by: John Z 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
Title: Re: Code, setting, or other that only includes include files that are used
Post by: alderman2 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.
Title: Re: Code, setting, or other that only includes include files that are used
Post by: TimoVJL on December 17, 2024, 04:30:28 PM
Map file can be useful to find out used object files
Title: Re: Code, setting, or other that only includes include files that are used
Post by: alderman2 on December 17, 2024, 06:22:45 PM
Good idea!
Why didn't I think of that before?
Title: Re: Code, setting, or other that only includes include files that are used
Post by: John Z 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
Title: Re: Code, setting, or other that only includes include files that are used
Post by: alderman2 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.  ;)
Title: Re: Code, setting, or other that only includes include files that are used
Post by: John Z 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
Title: Re: Code, setting, or other that only includes include files that are used
Post by: alderman2 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.
Title: Re: Code, setting, or other that only includes include files that are used
Post by: TimoVJL 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.
Title: Re: Code, setting, or other that only includes include files that are used
Post by: alderman2 on December 18, 2024, 08:10:22 PM
Glad you said that!
I'll look into it next time I work with Pelles.
Title: Re: Code, setting, or other that only includes include files that are used
Post by: HellOfMice 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!
Title: Re: Code, setting, or other that only includes include files that are used
Post by: John Z 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
Title: Re: Code, setting, or other that only includes include files that are used
Post by: HellOfMice on December 19, 2024, 04:17:37 PM
Thank you John for this nice answer.
I discover my addins too and said the same thing as you
:)