Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8609

General • Re: Assign variables to specific addresses?

$
0
0
The optimisation depends on where the volatile is.
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.

I assume you are talking about the difference between

Code:

*((volatile int*)0x1234)
and

Code:

*((int * volatile)0x1234)
or even

Code:

*((volatile int * volatile)0x1234)
but only the first one makes sense as the others are saying that the pointer itself is volatile yet in these examples it's not even variable, it's a literal constant.

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



Viewing all articles
Browse latest Browse all 8609

Trending Articles