Hacker News new | past | comments | ask | show | jobs | submit login

Definitely. Know your warning options! Also, try using multiple compilers. tcc compiles very quickly, clang often has better error messages, etc.

Speaking of variable shadowing: It's usually worth wrapping any preprocessor macros in a "do { ... } while (0)" block unless you deliberately want variable definitions to escape (in which case, token pasting a suffix is usually a good idea).




Isn't "do { ... } while (0)" the same as just "{ ... }"?

I sometimes use "{ ... }" to limit the scope of a variable that is only needed for a small section of code.


Former lets break'ing out, latter doesn't.


do { ... } while (0) makes your macro behave like a statement (i.e. the semicolon is mandatory)


Yes. I don't include the trailing semicolon in macro definitions, because I expect the macro to be followed by them:

    MACRO(foo);


({ ... }) does this too. (Is this GCC-specific?)


That is a gcc extension. The construct as a whole has the value of the last statement executed within. Usually an inline function is preferable since it achieves the same thing using only standard syntax.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: