Exploring My Technical Learnings... Which could be a doubt or solution..!
Sunday, November 22, 2009
On that day my mind thought about 'Global Static'
I had read the theory on static keyword, its role in the programming embedded systems. Also i taught in to some students about this. But till that, i never used 'static' in my real projects. At last, my mind throught about the use of 'static' keyword.
First i will tell you about the situation which made me to use the 'staitc' keyword.
I had a global function pointer say Gfptr( ) and in my INIT function of a module i was initializing the Gfptr() like following.
void (Gfptr)(void);
void INIT( )
{
void (*Lfunction)(void);
Lfunction = (FARPROC)GetprocAddress(hdll,"Adding");
Gfptr = (void*)function;
}
Here, Gfptr will be called moe than 1000 times ie., once for every 10ms. So that it can be called as 'reentrant'.
But, after some time, call to Gfptr() was failing. I was getting why...! After some time, i have printed the address of 'Gfptr' in the INIT itself, say 0x123456. Aslo i have printed the same before each call. Like,
printf("%x\n",Gfptr);
Gfptr();
I dont know why, after some time, address was printed wrongly...! Till that, address was still 0x123456. But after some time, it was not 0x123456....!
Then, 'global static' has come to mind and i made Gfptr as Global static. Then it was worked fine and i was happy...!!!
It was the first time, i thought the application of about GLOBAL STATICs.
From that time onwards, I thought to declare the global pointers as 'static'.
Subscribe to:
Posts (Atom)