Optimized Out variables | Cypress Semiconductor
Optimized Out variables
I have been having trouble with this optimizing out of variables in several projects and it seems I do not understand when this happens.
In the last case I had a variable defined within scope of a procedure (method) that retrieved info from a serial port buffer and used the value to store a record in SPI flash IC. I thought the variable would only be optimized out if I did not use it.
This is what I am doing:
level = buf*256 + buf;
StoreRecord(.....,level); //I though variable would be retained because I am using it in another function
In this case I had to set up "level" as volatile.
I thought it would only be optimized out if not used, like this...
Level = buf*256 + buf;
//then do nothing else with it