[En-Nut-Discussion] Hardware Register Access Using Volatile Pointer

Ulrich Prinz uprinz2 at netscape.net
Mon Apr 25 23:44:24 CEST 2011

> PS: reading into a dummy variable won't help, since the compiler is
> free to optimze dummy (and even real) variable away.
In addition newer versions of gcc will throw a warning "Variable
declared and set is not evaluated" or something similar.

But I have to check, as I probably did that some times in my code and
there where no problems, so the variable is definitely read and there
where no warnings, but that might be cause I used the variable multiple
times in this function.

Another way to force the non expensive way might be:

void fn( void)
    register int tmp;
    tmp = *(volatile int*)ioregister;

Through the compiler optimization any at that time not needed register
should be chosen and a real read is forced by not bugging any caching.


More information about the En-Nut-Discussion mailing list