Author Topic: Newbie confused over compiler define option  (Read 2813 times)

Offline SouthOfNorth

  • Single posting newcomer
  • *
  • Posts: 4
Newbie confused over compiler define option
« on: August 26, 2021, 06:34:48 am »
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.

 

   

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3026
Re: Newbie confused over compiler define option
« Reply #1 on: August 27, 2021, 11:18:25 pm »
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?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7191
    • My Best Post
Re: Newbie confused over compiler define option
« Reply #2 on: August 29, 2021, 01:03:31 am »
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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline SouthOfNorth

  • Single posting newcomer
  • *
  • Posts: 4
Re: Newbie confused over compiler define option
« Reply #3 on: October 19, 2021, 06:50:41 am »
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?