Silicomancer Silicomancer - 8 months ago 62
C Question

C99 static inline function with static local variable

If I write something like this in a C99 header:

static inline void f()
static int x = 0;
// Do something with x

Is it guaranteed that each module including this header gets a separate instantiation of
and its own instantiation of

Answer Source

Yes, by definition, that's what static means. The fact that it's in a header is irrelevant. Conceptually, the C preprocessor creates one file to compile per .c file as if you had just (re)typed all the text in the header into the .c yourself.