Thursday, 26 February 2009

#define( ignoreThisArgument ) 0

# commands are great for breaking things in novel ways, so they should be avoided like gotos. That is, avoided when necessary, used sparingly, sensibly.

things you may not know about the # commands:
  • They operate on text and text alone. They have no idea what a symbol is.
  • The #include command actually copy pastes the entine file inline into the buffer for compilation (which means you can #include anything you want in odd ways to create cool effects.)
  • The #if/#ifdef/#ifndef/#endif/#else blocks actually delete code from the source file buffer. Anything cut from the code in this way is never seen by the compiler
  • if you #define a macro, the macro code is placed inline for every time you use the #define, which can lead to a lot of code generated from a very small amount of code.
  • because #define actually replaces code, unused arguments can be filled with trash that wouldn't compile on an inline function
so, think about the pre-processor as being a text macro system for a completely different language and you'll be pretty close to what it really is.

No comments: