While true, I think this a red herring as nobody is suggesting the alternative placement of the volatile. Both your code and Hippy's code have the target of the pointer volatile but the pointer itself non-volatile.The optimisation depends on where the volatile is.
I assume you are talking about the difference between
Code:
*((volatile int*)0x1234)Code:
*((int * volatile)0x1234)Code:
*((volatile int * volatile)0x1234)Using a typedef can make the code more readable by making it more obvious which object the volatile keyword is attached to, but it doesn't alter the choice of things that you can do.
The issue with using structs vs individual global variables is nothing to do with the placement of volatile - it's about whether the compiler can know at compile time whether two variables are in adjacent locations.
Statistics: Posted by arg001 — Mon Mar 24, 2025 11:12 pm