gcc c&c++ extensions

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
firas981

gcc c&c++ extensions

Post 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)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:gcc c&c++ extensions

Post 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)
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:gcc c&c++ extensions

Post 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.
Post Reply