[gnu.g++] type of '\0'

ken@CS.ROCHESTER.EDU (06/24/89)

I've just been bitten by the failure of cc, gcc and g++ to detect this
kind of error.

main()
{
	char	*p = 0;

	if (p == '\0')
		printf("hmm...\n");
	if (p == '\001')
		printf("hmm...\n");
}

Obvious once you see it isn't it? But none of the compilers complained
about the first comparison, only the second one.

Now, I know about the ANSI rules for nil pointers and I know there are
no constants of type char, so '\0' is identical to 0. What I'm asking
is, could compilers be not so eager to promote '\0' to type int until
the constant is used? The hooks must be there, because g++ has the
-fchar-charconst flag.

ken@CS.ROCHESTER.EDU (Ken Yap) (06/24/89)

In case it wasn't clear what kind of (programmer) error I meant, have a
look at this segment of code:

	char	*p;

	for (p = string; p != '\0'; ++p)
		...