1

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 f() and its own instantiation of x?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.