[comp.lang.c] "the integer constant zero"

mouse@mcgill-vision.UUCP (der Mouse) (04/08/88)

In article <10754@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes:
> [	char *p; p = (0, 0); ]
> [...] the integer constant `0' in a pointer context [...].  What is
> `the integer constant 0'?  Clearly this is any constant expression
> whose value is zero and whose type is one of the integral types
> {char, short, int, long} or their signed or unsigned variants.

"the integer constant zero" is not necessarily the same as "an integer
constant expression zero".

It seems to me that the phrase could reasonably be taken to indicate
that only `0', standing alone, was sufficient.  I think I could make a
case that even putting parentheses around it would break it.

Does dpANS specify exactly what they mean by "the integer constant
zero"?  For example, p=0; assigns a nil pointer to p (assuming a
pointer type for p).  Does the draft make it clear whether p=0+0; also
does?  The RHS is a constant expression with value zero, but this is
not necessarily the same thing as "the [note definite article] integer
constant zero".

Now, how about

#define FIRST 0
char foo[10];  char *p;
p = &foo[FIRST] - &foo[0]; /* now waiiiit a minute.... */

That's constant expression whose value is a zero integer, isn't it?  Is
this wrong or just questionable style?

					der Mouse

			uucp: mouse@mcgill-vision.uucp
			arpa: mouse@larry.mcrcim.mcgill.edu

chris@mimsy.UUCP (Chris Torek) (04/08/88)

>In article <10754@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>>[...] the integer constant `0' in a pointer context [...].  What is
>>`the integer constant 0'?

In article <1032@mcgill-vision.UUCP> mouse@mcgill-vision.UUCP
(der Mouse) writes:
>"the integer constant zero" is not necessarily the same as "an integer
>constant expression zero".

My copy (or rather, Fred's copy, which I borrowed) of the draft
standard is Elsewhere at the moment, but what was `clear' to me
(constant 0 => expression that evaluates as a constant and to 0) was
apparently `clear' to X3J11 as well, because that was what the draft
said.

Now, however, there seems to be some sentiment to rephrase it.
Among other problems,

	int *p;
	p = 1 ? (void *)0 : (void *)0;

is not quite legal, even though

	p = 1 ? 0 : 0;

is!

This sort of nasty fiddly detail is what makes getting standards
right so hard.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris