Silicomancer Silicomancer - 1 year ago 114
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download