Importance of global variables

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 I was working with a project for PSoC5. I had many functions which were callling in chain. One of the function was passing the address of an array to other function (this array was of 300 bytes length) and inturn the called function was passing the array adddresss to other function. oh...seems like messing......  The final function was writing value to the specified address.

   

Compiler which allocates the local memory for a function messed up a bit and the arrray was written with a different value ( i was working with many variables in this function). Compiler might have thought that such a huge memory space for each local variable was not required and tried optimising the data space. 

   

So it is important to have any huge array to be a "global" to prevent messing with the compiler.

0 Likes
7 Replies