use of if (!cptr) and if (cptr), where cptr is a *)
der Mouse
mouse at mcgill-vision.UUCP
Fri Aug 18 17:18:07 AEST 1989
In article <1429 at cbnewsl.ATT.COM>, dfp at cbnewsl.ATT.COM (david.f.prosser) writes:
> In article <1603 at mcgill-vision.UUCP> mouse at mcgill-vision.UUCP (der Mouse) writes:
>> In article <660046 at hpclwjm.HP.COM>, walter at 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 at larry.mcrcim.mcgill.edu
More information about the Comp.lang.c
mailing list