Die, defines, die !

I have some gripes with C, though I use it sometimes. Macros are one of them.

  • They are hard to write as long as you use them for anything besides numeric constants, due to their horrible syntax
  • They are even harder to debug, because the C preprocessor takes care of them BEFORE error detection begins its work
  • They shouldn’t be needed. Macros are used for constants, functions with high performance constraints, and header protection. Constants should be declared the usual way (it works in C++, but not in C), high-performance functions should be inlined instead (works in C++, buggy in C99), and header protection should be a standard feature of the language

So in the last week-end, I tried to remove as much #defines from my code as I could, in order to make it cleaner and easier to debug. For some reason, this also resulted in my code compiling faster. The C preprocessor of GCC could be a bit slow.

Apart from that, well, I updated the doc to have it mirror the latest version of the code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s