Can static variables be declared in a header file?
You can’t declare a static variable without defining it as well (this is because the storage class modifiers
static and extern are mutually exclusive). A static variable can be defined in a header file, but this would
cause each source file that included the header file to have its own private copy of the variable, which is
probably not what was intended.
Cross Reference:
II.16: What is the difference between declaring a variable and defining a variable?
You can’t declare a static variable without defining it as well (this is because the storage class modifiers
static and extern are mutually exclusive). A static variable can be defined in a header file, but this would
cause each source file that included the header file to have its own private copy of the variable, which is
probably not what was intended.
Cross Reference:
II.16: What is the difference between declaring a variable and defining a variable?
No comments:
Post a Comment