Jens Gustedt's Blog

February 12, 2011

const and arrays

Filed under: C99, P99, syntax — Jens Gustedt @ 09:29

Qualifying a type with const may have some surprises. Consider the following

toto A = { 0 };
toto const* p = &A;

where toto is an opaque typedef that we don’t control. The question would be if the initialization of p is valid or not? From the way I pose that question, you have probably guessed the answer: it depends.
(more…)

Advertisements

February 2, 2011

Handling control flow inside macros

Filed under: C99, language, P99, preprocessor, syntax — Jens Gustedt @ 20:35

When people program macros that they want to be executed anywhere where a statement could be, they often use the

do {...} while(0)

construct. This construct has a big disadvantage in that it may change control flow in an unexpected way when you’d use it as a generic macro tool to collect statements:
(more…)

Create a free website or blog at WordPress.com.