Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr), where cptr is a *) Message-ID: <1618@mcgill-vision.UUCP> Date: 18 Aug 89 07:18:07 GMT References: <10099@mpx2.mpx.com> <660046@hpclwjm.HP.COM> <1603@mcgill-vision.UUCP> <1429@cbnewsl.ATT.COM> Organization: McGill University, Montreal Lines: 41 In article <1429@cbnewsl.ATT.COM>, dfp@cbnewsl.ATT.COM (david.f.prosser) writes: > In article <1603@mcgill-vision.UUCP> mouse@mcgill-vision.UUCP (der Mouse) writes: >> In article <660046@hpclwjm.HP.COM>, walter@hpclwjm.HP.COM (Walter Murray) writes: >>> As a further exam[p]le of the latitude you have in writing a null >>> pointer constant, the following would also be legal. >>> if (cptr == (signed short)0.3+sizeof(char)-'\1' >>> +sizeof((long int*)myfunc()+3,000)-sizeof'M'); >> [T]his is valid only if sizeof(long int *) equals sizeof(int), which >> isn't true everywhere. > Not as far as I can see. The relevant part of the expression is > sizeof((long int*)myfunc()+3,000)-sizeof'M' > and as the first sizeof expression is actually a (hidden) comma > expression, Argh. You are, of course, correct. (Strange how easy it is to misread 3,000 as 3000.) >> Your expression also requires that myfunc() be declared (possibly >> implicitly) as returning something that can be cast into (long int *); > Assuming no other information, then myfunc() is implicitly declared > to return int. That's what my "possibly implicitly" was intended to anticipate. >> [I]s it then possible to use this as a means of drawing a guaranteed >> compile-time warning if [sizeof(long int *) != sizeof(int)] [...]? > [Yes.] Just how useful this is is not at all clear. Well, no, I can't exactly claim to have a use in mind for it. But it seems like something that it might be nice to be able to do. (It's easy to check at run-time, of course, but not all compilers are bright enough to eliminate the dead code, and occasionally you can't afford the extra clutter.) der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu