difask's blog

By difask, 9 years ago, translation, In English

I have seen in many codes that structure like following is using :

#ifdef something

...

#endif

Where can I set up "something"? I use CodeBlocks. Thank you!

  • Vote: I like it
  • +8
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it +12 Vote: I do not like it

This can be done in the compiler settings of your IDE. Usually they allow you to pass some arguments to the compiler invocation. You need to pass the argument:

-D something

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

you could enable by putting #define something 1 before that #ifdef :

#define something
#ifdef something
...
#endif
»
9 years ago, # |
Rev. 3   Vote: I like it +2 Vote: I do not like it

This is a simple example for #ifdef, #ifndef and #else you can also have #elif which works like else if and there is #if that works like if;

#define HelloWorld

#ifdef HelloWorld
#define ByeWorld
// This line will be executed
#else
#define HelloWorld
// This line won't be executed
#endif

#ifndef HolaMundo
#define HolaMundo
// This line will be executed
#else
#define AdiosMundo
// This line won't be executed
#endif
»
9 years ago, # |
  Vote: I like it +13 Vote: I do not like it

For Codeblocks: Settings -> Compiler.

If you invoke gcc manually: g++ -DSOMETHING ...