This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Incrementing volatiles?


Hi,

Bill Currie:
> 
> and "return foo++" could be
> 
> bar:
>     movl  foo,%eax
>     incl  foo
>     ret
> 
Wrong. The foo++ means "read it, perhaps do something with the value,
increment the value, put it back". Your assembly code reads the value
twice.

> Now, if I'm really off track, can someone please give me some pointers
> to information that will set me right?
> 
"volatile" is massively undefined. My off-the-seat-of-my-pants definition
is that volatile variables are _always_ accessed exactly as many times, and
in exactly that order, as described in the C source code.

How to tell the backend (Intel or otherwise) that sometimes(!) it can
combine a read-add_one-write insn sequence into one "incr", even if the
to-be-incremented thing in question is marked as volatile, is an
interesting question. IMHO, however, "two volatiles never match" is a bit
too strong.

-- 
Matthias Urlichs
noris network GmbH


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]