Article View: gnu.g++
Article #11type of '\0'
From: ken
Date: Fri, 23 Jun 1989 20:39
Date: Fri, 23 Jun 1989 20:39
21 lines
991 bytes
991 bytes
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.
Technical Details
Message-ID:
<8906232039.AA12649@cursa.cs.rochester.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!CS.ROCHESTER.EDU!kenShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!CS.ROCHESTER.EDU!ken From: ken@CS.ROCHESTER.EDU Newsgroups: gnu.g++ Subject: type of '\0' Message-ID: <8906232039.AA12649@cursa.cs.rochester.edu> Date: 23 Jun 89 20:39:27 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 21