User forums > Using Code::Blocks

Newbie confused over compiler define option

(1/1)

SouthOfNorth:
Hello, I am new to code::blocks. 

 I have a C source file with conditional code dependent upon the compiler selected.    The code may say "#If defined( __SDCC__)" and do some things, or do something else if not SDCC, or if  another compiler specified.      If there is a definition in the source file, the applicable code highlights.    In my code right now, the SDCC selection is not defined and the code I wish to execute is not highlighted.   How is the compiler selection indicated to the preprocessor at compile time?

I am concerned the SDCC compiler is executing, but not conditionally compiling my code properly.

 

   

BlueHazzard:
The highlighting of #ifdef blocks is complete independent from the compiling and only visually. It does not know anything about the selected compiler. You can turn  it of in the settings if it is distracting you

Codeblocks does not define anything by default and all #ifdefs come from the compiler itself.

What exactly is your problem?

stahta01:
I used this feature a long time ago.

Settings -> Editor
Left Pane: General Settings
Tab: C/C++ Editor Settings
Check mark: Include Host Platform defines

That is what I think used years ago.

Tim S.

SouthOfNorth:
Thanks for these answers, but still not clear to me.  I have a program with SDCC compiler specified in the build options.  In the main.c code, there is a preprocessor command:

#if defined(SDCC)
statements
#endif

But I don't actually have a #define(SDCC) statement in main.c  so statements don't get highlighted.   But those are the statements that will get compiled because SDCC is specified in the build option, presumably it inserts the directive when building.  But when viewing the code in the editor, this is irritating because you can't see which statements will compile.  If I add a #define in the program, then they highlight in the editor.   Is that what I have to do visualize the code properly?   What exactly does "Include Host Platform defines" change?

Navigation

[0] Message Index

Go to full version