Xref: utzoo comp.unix.ultrix:4897 comp.sys.mips:1099 comp.sys.sgi:6230 Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!mtxinu!sybase!mcfong@mercury.sybase.com From: mcfong@mercury.sybase.com (Martin C. Fong) Newsgroups: comp.unix.ultrix,comp.sys.mips,comp.sys.sgi Subject: Effect of 'volatile' on structures Message-ID: <11261@sybase.sybase.com> Date: 11 Oct 90 19:16:05 GMT Sender: news@Sybase.COM Organization: Sybase, Inc. Lines: 86 I believe my earlier confusion about the "volatile" declaration as implemented on the RISC ULTRIX C compiler is due to a bug in the compiler. The issue is whether the fields within a structure are considered "volatile" if only the structure is declared "volatile". On a MIPS RISComputer, OS Version 4.0, this is true. On SGI IRIX, OS Version 3.2 and DEC RISC ULTRIX, Version 3.0, this is *not* true. On the latter two platforms, fields within a "volatile" structure must be further declared "volatile" if the field is a pointer. The attached program will demonstrate the problem. The program *must* be compiled with "-O". The MIPS machine produces the following results: a{i,j} = {0,0} b{i,j} = {1,1} c{i,j} = {1,1} while the SGI and DEC machine produces these results: a{i,j} = {0,0} b{i,j} = {1,0} c{i,j} = {1,1} Could someone please try this program on RISC ULTRIX 4.0 and SGI IRIX 3.3? Because the MIPS machine produces the "expected" results, I will assume that the behavior on the SGI and DEC machines is due to the fact that SGI and DEC and behind in MIPS C compiler bug fixes. I would like to know if DEC and SGI have caught up on these bug fixes in their later releases (neither of which I have). Thanks. Martin C. Fong Sybase Inc. 6475 Christie Ave. Emeryville, CA 94607 (415)596-3822 sun!sybase!mcfong mcfong@sybase.com decwrl::"@tis.llnl.gov:mcfong@sybase.com" =================================== CUT HERE =================================== #include main() { jmp_buf env; struct { int i; int * j; } a; volatile struct { int i; int * j; } b; volatile struct { int i; int * volatile j; } c; a.i = b.i = c.i = 0; a.j = (int *) 0; b.j = (int *) 0; c.j = (int *) 0; if (setjmp(env)) { printf("a{i,j} = {%d,%d}\n", a.i, a.j); printf("b{i,j} = {%d,%d}\n", b.i, b.j); printf("c{i,j} = {%d,%d}\n", c.i, c.j); } else { a.i = b.i = c.i = 1; a.j = (int *) 1; b.j = (int *) 1; c.j = (int *) 1; longjmp(env); } }