This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Does the keyword volatile work?
- From: Michael Eager <eager at eagercon dot com>
- To: "Stephen P. Smith" <ischis2 at cox dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 13 May 2003 09:00:23 -0700
- Subject: Re: Does the keyword volatile work?
- References: <3EBFD2E4.2090606@cox.net>
Stephen P. Smith wrote:
In the code fragment below which was produced with a 3.3 version of the
gcc compiler,
why isn't the variable p1 assigned to mailboxHandle immediately? I
believe that the
keyword volatile should cause that to happen. BTW, the same behaviour
has been observed
with the 2.95.2 compiler.
Volatile is an attribute of objects, not values. Casting the value of
p1 to volatile doesn't really do anything. It doesn't make either p1
or mailboxHandle volatile.
Volatile also does not mean "do this immediately". The compiler may
move code before or after assignment to a volatile so long as accesses
to volatile variables all occur in order.
Command Line (-I -D switches removed for clarity):
i686-pc-elf-gcc -nostdinc -nostdinc++ -Wall -W -fno-exceptions
-march=i586 \
-D__stdcall="__attribute__((__stdcall__))"
-D__cdecl="__attribute__((__cdecl__))" \
-c -g -O3 -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -fno-rtti
-fcheck-new \
-g -Wa,-a,-ad -o ipck.lst.temp ipck.cpp > ipck.lst
Code Fragment:
819:../../code/ipc/ipck.cpp **** DWORD CDECL someFunction(DWORD,DWORD
p1,DWORD p2,DWORD p3,DWORD,DWORD)
820:../../code/ipc/ipck.cpp **** {
2664 .LM230:
2665 06d0 55 pushl %ebp
2666 06d1 89E5 movl %esp, %ebp
2667 06d3 57 pushl %edi
2668 06d4 56 pushl %esi
2669 06d5 53 pushl %ebx
2670 06d6 83EC0C subl $12, %esp
2672 .Ltext123:
2674 .LM231:
2675 .LBB297:
2676 .LBB298:
2677 .LBB299:
2678 06d9 A1000000 movl _ZN9Scheduler16itsRunningThreadE, %eax
2678 00
2680 .Ltext124:
821:../../code/ipc/ipck.cpp ****
822:../../code/ipc/ipck.cpp **** GenericHandleTYP var1 =
(GenericHandleTYP)((volatile DWORD)p1);
823:../../code/ipc/ipck.cpp **** bool var2 = (bool)p2;
824:../../code/ipc/ipck.cpp **** timeoutSpecifier var3 =
(timeoutSpecifier)p3;
--
Michael Eager Eager Consulting eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077