Page 1 of 1

gcc c&c++ extensions

Posted: Wed Mar 03, 2004 1:21 am
by firas981
I am very good at c++ , however i am new to gcc (c&c++)
extensions ......
i read gcc documentation , but i still confused about several things :
1)why we use 'volatile' with 'asm' , and what the meaning of it ?
2)

Re:gcc c&c++ extensions

Posted: Wed Mar 03, 2004 2:30 am
by Solar
'volatile' is hardly a gcc specific extension - it's part of the language standard(s). It tells the compiler that the storage location identified could change even while the running program doesn't write to it (for example, due to an interrupt, or because it's shared memory, or...), so the value isn't cached in a CPU register, but actually read from memory upon each access.

I hope that helps; or have I misunderstood your question?

As for 2), I have no idea myself. 8)

Re:gcc c&c++ extensions

Posted: Wed Mar 03, 2004 6:01 am
by Pype.Clicker
@solar: this is for "volatile int interrupt_flag", not for " asm volatile("some-operation":...);

the meaning is basically the same: the 'volatile' modifier prevent the compiler to optimize asm instructions that appear to have "no effect" on the computation for him. An ASM instruction that has no output, for instance, or which generate results that are never used by the C/C++ code might be skipped by the optimizer under some strange circumstances (not well understood by your humble servant).

So making every 'asm' instruction 'volatile' aswell is a way (hack?) to ensure that the expected bytes will *indeed* be generated.