Effect of 'volatile' on structures

Martin C. Fong mcfong at mercury.sybase.com
Fri Oct 12 05:16:05 AEST 1990


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 at sybase.com
decwrl::"@tis.llnl.gov:mcfong at 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);
	}
}



More information about the Comp.sys.sgi mailing list