A Little Quibble

mcdaniel at uicsrd.csrd.uiuc.edu mcdaniel at uicsrd.csrd.uiuc.edu
Thu Dec 8 16:14:00 AEST 1988


Suppose I compile the following program under some dpANS C compiler:

    #include <stdio.h>
    main()
        {
	int a;
	a = 1;
	    {
	    int a = a;	/* X */
	    printf("a=%d\n", a);
	    }
	exit(0);
	}

Does dpANS require that "1" be printed, or is the result not defined
by dpANS?  In other words, in what environment is the right-hand-side
of line X evaluated?

Suppose I change line X to
	int b = a;    /* X' */
	int a = b;
Does the result change?  If the simplest translation
	int b, a;
	b = a; a = b;
is always done, the result is always undefined.

I ask this for two reasons:
- it's an interesting little quibble. :-)
- I would like to declare an invariant like this:
	double nubie;
	. . . compute nubie . . .
	{const double nubie = nubie;
	    . . . here, nubie is invariant . . .
	}

(I could also put "register" there to prevent passing "&nubie" to a
function to change it.  This use would only be for a compiler that is
smart enough to do its own register allocation, and ignore me totally.
:-)

By the way, here's another place where "typeof" would be convenient.
I could use
	#define FIX(x)	const typeof(x) x = x;
and code the example as
	{ FIX(nubie);
	. . . invariant nubie . . .
	}
Instead, I must use
	#define FIX(type, x)	const type x = x;
This is more error-prone, and it is harder to change the type of such
a FIXed variable.

--

             Tim, the Bizarre and Oddly-Dressed Enchanter

Center for      |||  Internet, BITNET:  mcdaniel at uicsrd.csrd.uiuc.edu
Supercomputing  |||  UUCP:     {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel
Research and    |||  ARPANET:  mcdaniel%uicsrd at uxc.cso.uiuc.edu
Development,    |||  CSNET:    mcdaniel%uicsrd at uiuc.csnet
U of Illinois   |||  DECnet:   GARCON::"mcdaniel at uicsrd.csrd.uiuc.edu"



More information about the Comp.std.c mailing list