Unlock the Gateway: Join the Embed Threads
Unlock the Possibilities: Dive In with Login Access
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use of static variable declaration in a header file included in multiple .c files
Here we declare variable as a global scope. If a variable is declared as static at the global scope within a header file (.h file) that is included in multiple .c files, each translation unit (.c file) will have its own private copy of that variable. This means that each file that includes the headeRead more
Here we declare variable as a global scope.
If a variable is declared as static at the global scope within a header file (.h file) that is included in multiple .c files, each translation unit (.c file) will have its own private copy of that variable. This means that each file that includes the header will have its own independent instance of the variable, even though they have the same name.
However, it’s worth noting that including a header file with static variables in multiple translation units can lead to a waste of memory, as each file will have its own separate copy. In general, it is considered best practice to avoid defining variables in header files and instead declare them as extern in the header and define them in a single source file to maintain a single instance of the variable
See less