Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Pointer to a local variable

$
0
0
Hi all,
I have a coding guideline that I need to avoid using dynamic memory allocation. In stead of it, I do things like this:

typedef struct
{
u32 id;
....
} A;

void test()
{
A instance;
A* pinstance = &instance;
pinstance->id = 0xa000111;
(do everything with pinstance)
....
 -> pinstance->id has different value (0x111) even though it is not set any where else!
}


Can any one pls tell me:
1. If this is a good way to do.
2. What can be possible cause of the change of the value of pinstance->id. Can it be because of stack memory full? the thread is still running normally, only the local variable value is changed. It seems that the problem occured when optimization is on (-O3).
Thanks,Lam

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>