[comp.unix.ultrix] Effect of 'volatile' on structures

mcfong@mercury.sybase.com (Martin C. Fong) (10/12/90)

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 <setjmp.h>

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);
	}
}

mjr@hussar.dco.dec.com (Marcus J. Ranum) (10/12/90)

In article <11261@sybase.sybase.com> mcfong@mercury.sybase.com (Martin C. Fong) writes:
>
>Could someone please try this program on RISC ULTRIX 4.0

	Machine is running RISC ULTRIX 4.0:

hussar.dco.dec.com-> make goo
cc -O  goo.c -o goo
hussar.dco.dec.com-> goo
a{i,j} = {0,0}
b{i,j} = {1,0}
c{i,j} = {1,1}
hussar.dco.dec.com->

mjr.
-- 
 coffeecoffeecoffeecoffeecoffeecoffeecoffeecoffeecoffeecoffeecoffeecoffeecoffee

hartzell@boulder.Colorado.EDU (George Hartzell) (10/13/90)

In article <11261@sybase.sybase.com>, mcfong@mercury (Martin C. Fong) writes:
>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



On a DECstation 3100 running 4.0:
cc -O -o foo foo.c
foo
 a{i,j} = {0,0}
 b{i,j} = {1,0}
 c{i,j} = {1,1}

cc  (cc)
        Mips Computer Systems 2.0

g.
George Hartzell			                  (303) 492-4535
 MCD Biology, University of Colorado-Boulder, Boulder, CO 80309
hartzell@Boulder.Colorado.EDU           ..!ncar!boulder!hartzell