If I declared a static variable in a header file, and the header file is included in a couple of .c files. Is there any problem?
Thanks
Yes and no. This will create a different static variable in each .c you compile. To solve this, declare it as "extern" as well, this will tell the compiler to look for all other declarations of the same variable and "merge" them into a single one. Of course, if having a different static variable in each .c you compile is what you are looking to do, them it's fine.. as far as I know, but I never use global variables anyways, it's not recommended to do so, look at this.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.