static int x[2], *p = x+(x-x); ?

Paul Eggert eggert at ata.twinsun.com
Fri Sep 14 11:52:41 AEST 1990


ANSI C 3.4 (page 56 lines 22-27) says:

	More latitude is permitted for constant expressions in initializers.
	Such a constant expression shall evaluate to one of the following:

	o	an arithmetic constant expression,
	o	a null pointer constant,
	o	an address constant, or
	o	an address constant for an object type plus or minus an
		integral constant expression.

What does ``evaluate to'' mean here?  I thought evaluation yields a value
(see 3.1.5), but here it seems to yield an expression.  For example, which
of the following declarations are OK, and why?

    static int x[2];
    static int *p = 1 + x; /* int+addr, not addr+int */+
    static int *q = x + (int)(0.1 + 0.9); /* Does this ``evaluate to'' x+1? */
    static int *r = &x[(int)(0.1 + 0.9)]; /* Is this equivalent to the above? */
    static int *s = x + (x-x); /* Does this ``evaluate to'' x+0? */


A nit: the phrase ``pointer to an lvalue ... or to a function designator''
(lines 32-33) is sloppy, because lvalues and function designators are
_expressions_, while pointers point to _objects_.



More information about the Comp.std.c mailing list