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

Christopher R Volpe volpe at underdog.crd.ge.com
Sat Sep 15 06:05:56 AEST 1990


In article <2699 at rossignol.Princeton.EDU>, drh at cs.Princeton.EDU (Dave
Hanson) writes:
|>        static int *s = x + (x-x); /* Does this ``evaluate to'' x+0? */
|>
|>even though (x-x) is 0, compilers may not be obliged
|>to recognize it as 0 because x-x doesn't conform to the allowable
|>expressions you listed above.

Yes, they are obliged to recognize it as zero because the two 
operands (which happen to be identical) are both pointers into
the same array. See K&R II A7.7
                                    
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com



More information about the Comp.std.c mailing list