pointer checking
Danny
danny at itm.UUCP
Thu Feb 18 01:04:11 AEST 1988
In article <228 at gandalf.littlei.UUCP> martin at littlei.UUCP (martin) writes:
~...
~sizeof(ptr) != sizeof(int). I know that C does not gripe if
Yes, indeed, it is wrong to assume that sizeof (ptr) == sizeof (int),
BUT: read on!
~Example:
~
~char *ptr;
~
~if (ptr) { /* WRONG !!!!!! */
~ do something
~}
Would you expect a C compiler to generate erroneous code for the
following?
char a;
int b;
long c;
double d;
if (a) {
...
if (b) {
...
if (c) {
...
if (d) {
...
The compiler knows exactly what size each of the above types is.
Pointers, as far as comparison goes, are exactly the same.
Any compiler that doesn't properly compile
char *p;
if (p) {
do something;
}
is broken. The compiler knows the size of the pointer, and _should_
compare against the same size of a constant zero.
Danny
--
Daniel S. Cox
(seismo!gatech!itm!danny)
More information about the Comp.sources.bugs
mailing list