Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!decwrl!pa.dec.com!shlump.nac.dec.com!tkou02.enet.dec.com!jit345!diamond From: diamond@jit345.swstokyo.dec.com (Norman Diamond) Newsgroups: comp.lang.c Subject: Re: An Ubiquitous C bug Message-ID: <1991Jan21.083106.7297@tkou02.enet.dec.com> Date: 21 Jan 91 08:31:06 GMT References: Sender: news@tkou02.enet.dec.com (USENET News System) Reply-To: diamond@jit345.enet@tkou02.enet.dec.com (Norman Diamond) Followup-To: comp.lang.c Organization: Digital Equipment Corporation Japan , Tokyo Lines: 29 In article s64421@zeus.usq.EDU.AU (house ron) writes: >Here's a bug which exists in every single DOS C compiler I can find, >and may also exist on others: >In the small memory model, it is possible for a function to have the >address NULL. E.G.: >void x() {} >main() { > void (*y)() = x; > if (y==NULL) printf ("AARRGGHH!!\n"); >} >This sort of program CAN print the message if x() happens to be >loaded by the linker at the start of the code segment (address 0). According to section 3.2.2.3: "An integral constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. If a null pointer constant is assigned to or compared for equality to a pointer, the constant is converted to a pointer of that type. Such a pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object type or function." Every single DOS compiler that you can find is non standard-conforming. >Perhaps on some machines, NULL should _not_ be 0? Of course. On many many architectures, a bit pattern of all 1's would be suitable and very very useful. -- Norman Diamond diamond@tkov50.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it.