Newsgroups: comp.lang.c Path: utzoo!telly!robohack!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Subject: Re: What C compilers have non-zero null pointers? Message-ID: <1990Jul17.123627.1932@druid.uucp> Organization: D'Arcy Cain Consulting, West Hill, Ontario References: <9007161750.AA00664@edison.CHO.GE.COM> Date: Tue, 17 Jul 90 12:36:27 GMT In article <9007161750.AA00664@edison.CHO.GE.COM> rja writes: >I used to use a compiler for MSDOS and the 80x86 cpus >whose NULL pointer was F000:0000 hex when examined via >a debugger. It of course did compile fine as long as one >used sense and compared pointers to NULL rather than >a constant of zero... > Which compiler was that? I hope it didn't claim to be ANSI compatible. The NULL pointer does not have to be represented in memory as all zero bits but it does have to be represented by the string "0" in the context of a pointer comparison. Comparing a pointer to 0 is always correct and does not have anything to do with the internal representation of the NULL pointer. However I always use NULL for two reasons. Broken compilers on brain dead CPUs and if NULL is defined as "(void *)0" then it tests for accidentally testing a NULL pointer against a non pointer variable. For example: int a = 0; if (a == NULL) do(something); If tested against 0 the compiler won't complain but it will complain if it is tested against (void *)0. At least GNU C complains. In other words, use NULL not because 0 may not be the NULL pointer but because NULL can't be anything else. -- D'Arcy J.M. Cain (darcy@druid) | Government: D'Arcy Cain Consulting | Organized crime with an attitude West Hill, Ontario, Canada | (416) 281-6094 |