Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
enqk
on Oct 14, 2011
|
parent
|
context
|
favorite
| on:
What is your favourite C programming trick?
do { ... } while (0) makes your macro behave like a statement (i.e. the semicolon is mandatory)
silentbicycle
on Oct 14, 2011
|
next
[–]
Yes. I don't include the trailing semicolon in macro definitions, because I expect the macro to be followed by them:
MACRO(foo);
rcfox
on Oct 14, 2011
|
prev
[–]
({ ... }) does this too. (Is this GCC-specific?)
mansr
on Oct 14, 2011
|
parent
[–]
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: