references to dereferenced null pointers

Karl Heuer karl at haddock.ima.isc.com
Fri Mar 16 10:34:58 AEST 1990


In article <945 at ns-mx.uiowa.edu> williams at umaxc.weeg.uiowa.edu.UUCP (Kent Williams) writes:
>The bottom line in actual practice is that if NULL isn't a binary object
>of all zero bits, you can get into trouble porting programs.  Using 0 and
>NULL interchangebly is an unfortunate but common practice -- see code
>examples in Stroustroup's C++ book -- many assignments of 0 to pointers.

As I just finished saying, those are quite legal and do not cause a problem on
"strange-NULL" implementations.  (I presume we're talking about *constant* 0.)

>would be aided by a compiler that would flag ALL assignments of
>non-pointer constants to pointer variables.

I would hope that *any* modern compiler would flag a pointer-vs-int collision!

>[An explicit pointer-to-integer cast can still cause problems]
>[Also, some programs use small integer constants as sentinels]

I'll admit that these two are problem situtations, but I doubt they're all
that common.  And you don't have to have a "strange-NULL" architecture for
them to break.

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint



More information about the Comp.lang.c mailing list