An Ubiquitous C bug

Doug Gwyn gwyn at smoke.brl.mil
Tue Jan 22 08:09:07 AEST 1991


In article <s64421.664471332 at zeus> s64421 at zeus.usq.EDU.AU (house ron) writes:
>In the small memory model, it is possible for a function to have the
>address NULL.

[Meaning that a pointer to a legitimate function can compare equal to a
null pointer constant.]  This would be a non-conforming implementation,
and one would hope that an example similar to the one you gave is part
of any C validation suite.

>Perhaps on some machines, NULL should _not_ be 0?

No, in the SOURCE CODE, "0" MUST be an allowed way of writing a null
pointer constant.  This does NOT mean that the compiler has to produce
an all 0-bits representation for a null pointer constant, however; it
could for example use an all 1-bits representation, or the address of
a reserved library object.

>After all, it would be easy to prevent functions being
>loaded at address 1 (for example) on a DOS machine.

That's another solution.



More information about the Comp.lang.c mailing list