[oss] [Lab 03][Task 4] volatile keyword

Lucian Mogosanu lucian.mogosanu at gmail.com
Tue Oct 28 14:43:52 EET 2014


On Tue, Oct 28, 2014 at 02:22:57PM +0200, Alex Teaca wrote:
> Hello,
> 
> I see in get_got routine that the plt_ptr, got_min and got_max
> variables are marked with the volatile keyword.
> What is its purpose, is there a danger  for these variables
> to be modified, and the compiler don't see it ?

Not sure about got_min and got_max, but plt_ptr *must* be volatile. What the
volatile keyword does is it tells the compiler to not make any assumptions
about the data stored at that particular pointer (e.g. the compiler could make
the assumption that the value at plt_ptr doesn't change during execution, when
in fact it does/it may, only this is done transparently by the OS when some
plt-linked library function gets called).

As additional reading, this post [1] gives a more in-depth explanation of
how volatile generally works.

[1]: http://www.barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword

Lucian


More information about the oss mailing list