🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3642

NULL-pointers are not equal

#3642
From: Rune Huseby
Date: Thu, 03 Aug 1995 15:45
34 lines
1511 bytes
In Visual C++ 1.5 and Borland C++, the following example prints "false", even 
though section 6.2.2.3 of the standard gives that it should print "true"

void main(void)
{
  int *ptr1 = NULL;
  int __far *ptr2 = NULL;
  
  if(ptr1 == ptr2)
     printf("true");
  else
     printf("false");     
}

(FYI, the __far keyword tells the compiler to store the segment and offset in 
the variable, while the other only stores the offset, and uses the default 
data segment)

What happens, is that ptr2 contains 0 in both segment and offset, while ptr1, 
when converted (auto-casted) to the type of ptr2, gets the value of the 
default data segment in its segment part.

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.

Is the above behaviour incompatible with the standard, or do the standard 
somewhere say something about 'modified' pointers? (I have looked, but not 
found)

-- 
Rune Huseby, System Engineer, Imaging Division
GPI A/S, Pb. 12 Furuset, N-1001 OSLO, NORWAY
E-Mail: rune.huseby@gpi.telemax.no 
Technical Details
Message-ID: <3vqqtu$2r9@nms.telepost.no>
Path: arc1-ca.pugleaf.net!telepost.no!usenet

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!telepost.no!usenet
From: Rune.huseby@gpi.telemax.no (Rune Huseby)
Newsgroups: comp.std.c
Subject: NULL-pointers are not equal
Date: 3 Aug 1995 15:45:02 GMT
Organization: GPI
Message-ID: <3vqqtu$2r9@nms.telepost.no>
NNTP-Posting-Host: rhu.gpi.no
Mime-Version: 1.0
Content-Type: Text/Plain; charset=ISO-8859-1
X-Newsreader: WinVN 0.99.5