News:

Let's find out together what makes a PIC Tick!

Main Menu

Pre-processor $if vs Include priority

Started by trastikata, Oct 05, 2025, 03:26 PM

Previous topic - Next topic

trastikata

Hello,

maybe this is a question for Les...

My goal was to include only the relevant *.inc files, based on a $define parameter. But I've found that the pre-processor will include all files in a pre-processor $if statement which significantly slows down the compiling process, as well as the pre-processor will look into all included files and an erroneous pre-processor statement in any of those files will mess the code, even-though the file in question is not relevant as per the  $if statement ... for example:

If I only include the file I want, the pre-processing time is very short:

Include "TftLib\System\System_SPI_V1.inc"

However if I include files based on pre-processor statement this will extend the pre-processing time and as stated earlier an erroneous pre-processor statement in any of those files will mess the code, even-though the file in question is not relevant as per the  $if statement 

$define TFT_IC GC9307A

'============================================ GCxxxx ==================================================
$if TFT_IC = GC9A01
    Include "TftLib\System\System_SPI_V1.inc"
$elseif TFT_IC = GC9107
    Include "TftLib\System\System_SPI_V1.inc"
$elseif TFT_IC = GC9307
    Include "TftLib\System\System_SPI_V1.inc"
$elseif TFT_IC = GC9307A
    Include "TftLib\System\System_SPI_V1.inc"
'============================================ ILIxxxx ==================================================     
$elseif TFT_IC = ILI9225
    Include "TftLib\System\System_SPI_V3.inc"          
$elseif TFT_IC = ILI9225B
    Include "TftLib\System\System_PAR_V1.inc"
$elseif TFT_IC = ILI9341
    Include "TftLib\System\System_SPI_V4.inc"   
$elseif TFT_IC = ILI9342
    Include "TftLib\System\System_SPI_V1.inc"
$elseif TFT_IC = ILI9486
    Include "TftLib\System\System_PAR_V2.inc"
$elseif TFT_IC = ILI9488 
    Include "TftLib\System\System_SPI_V2.inc"     
'============================================ NVxxxx ==================================================    
$elseif TFT_IC = NV3007
    Include "TftLib\System\System_SPI_V1.inc"
$elseif TFT_IC = NV3023B
    Include "TftLib\System\System_SPI_V1.inc"
'============================================ NTxxxx ==================================================     
$elseif TFT_IC = NT35510   
    Include "TftLib\System\System_PAR_V3.inc"
'============================================ STxxxx ==================================================     
$elseif TFT_IC = ST7735
    Include "TftLib\System\System_SPI_V1.inc"
$elseif TFT_IC = ST7735S   
    Include "TftLib\System\System_SPI_V1.inc"
$elseif TFT_IC = ST7789   
    Include "TftLib\System\System_SPI_V1.inc"
$elseif TFT_IC = ST7789V    
    Include "TftLib\System\System_SPI_V1.inc"      
$elseif TFT_IC = ST7796S
    Include "TftLib\System\System_PAR_V4.inc"                                        
$endif

top204

#1
The Loader program first scans the .bas code listing, and whenever it sees any 'Include' directives, it will load in the code from them, and add file name and line numbers to them, so the main compiler knows where they belong. It will also do the same for any 'Include' directives within include files, so they are scanned, and on and on...

Once all the include files have been loaded, and the loader has added important information for the compiler to each line, and extracted important information from the code lines for the preprocessor to know what type of device it is scanning, and speed etc, and has created a temporary file, it calls the preprocessor with it, and this scans "all" of the program code, including the code from any include files that were present, and blocks or allows any code within them.

So if a lot of include files are used, all of their code lines will be loaded into the file, and the preprocessor has to go through all of the lines in there, and examine it, so it will take longer.