Diffenentiate between an internal static and external static variable?
by Vijayaprasad[ Edit ] 2010-02-16 10:03:18
An internal static variable is declared inside a block with static storage class whereas an external static variable is declared outside all the blocks in a file.An internal static variable has persistent storage,block scope and no linkage.An external static variable has permanent storage,file scope and internal linkage.
Internal static variable is block scope and persist there value between calls. External static variables are file scope. Normally when you need to declare global variable, it is good practices if you declare it as static for that particular file and provide interface function to access that global variable. This avoids accidentally modification of global variable.
e.g.
file 1
static int count;
int get_count()
{
return count;
}
void set_count(int cnt)
{
count = cnt;
}
so here other files can access count only by these functions.