Article View: comp.std.c
Article #3645Re: NULL-pointers are not equal
From: Mark Brader
Date: Thu, 03 Aug 1995 17:06
Date: Thu, 03 Aug 1995 17:06
48 lines
2090 bytes
2090 bytes
Rune Huseby (Rune.huseby@gpi.telemax.no) writes:
> In Visual C++ 1.5 and Borland C++, the following example prints "false",
> even though section 6.2.2.3 of the standard ...
Since there isn't a C++ standard yet, I assume we are talking about this
program as C, not C++.
> gives that it should print "true"
Does not.
> void main(void)
Undefined behavior; main() should return int.
> {
> int *ptr1 = NULL;
> int __far *ptr2 = NULL;
Syntax error; a diagnostic is required. __far is not a C keyword, and
an identifier is not allowed in that position. (Obviously, in the
implementations you're using it is an extension; the implementation
is at liberty to simply note this fact and continue.)
> if(ptr1 == ptr2)
> printf("true");
Undefined behavior: variadic function called without being declared first
(Fix: #include <stdio.h>).
> The first time I encountered this problem, I had a hard time tracking it
> down, since I've always believed that a NULL pointer is always equal to
> another NULL pointer.
It is -- if you give the implementation a strictly conforming program.
By using __far, you have told the implementation that you are not using
standard C; once you do that, you lose the protection of the standard.
See the signature quote.
(The two instances of undefined behavior also lose the protection of the
standard for you, but in practice aren't harmful on most implementations.
However, you should still avoid making these errors.)
--
Mark Brader | "It is impractical for the standard to attempt to
msb@sq.com | constrain the behavior of code that does not obey
SoftQuad Inc., Toronto | the constraints of the standard." -- Doug Gwyn
This article is in the public domain.
Technical Details
Message-ID:
<1995Aug3.170621.9636@sq.sq.com>Path:
arc1-ca.pugleaf.net!spool.mu.edu!torn!sq!msbReferences:
<3vqqtu$2r9@nms.telepost.no>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!spool.mu.edu!torn!sq!msb From: msb@sq.sq.com (Mark Brader) Subject: Re: NULL-pointers are not equal Message-ID: <1995Aug3.170621.9636@sq.sq.com> Organization: SoftQuad Inc., Toronto, Canada References: <3vqqtu$2r9@nms.telepost.no> Date: Thu, 3 Aug 95 17:06:21 GMT