Why we cant used static with extern ?
First I try to explain static:--
Static as a global variable is visible only in its defined file that means internal linkage and the value of static variable exist until the termination of program.
Static as a local variable or in a function or block it's visibility limit to that block. The value assigned to static variable during the first call remains in it for next call.
Extern
Extern is used to give a reference of global variables so that it is visible to all files in a project and you can use it.
But as per my question you can't used static with extern.........
for example you have a .h file in which you declare a variable extern int i;, now you want to used it as static in .c or .cpp file like "static int i=0" then here you get a compiler error because of visibility scope of extern and static and due to restriction of static you can't used one static variable in different file.
First I try to explain static:--
Static as a global variable is visible only in its defined file that means internal linkage and the value of static variable exist until the termination of program.
Static as a local variable or in a function or block it's visibility limit to that block. The value assigned to static variable during the first call remains in it for next call.
Extern
Extern is used to give a reference of global variables so that it is visible to all files in a project and you can use it.
But as per my question you can't used static with extern.........
for example you have a .h file in which you declare a variable extern int i;, now you want to used it as static in .c or .cpp file like "static int i=0" then here you get a compiler error because of visibility scope of extern and static and due to restriction of static you can't used one static variable in different file.
No comments:
Post a Comment