Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: DJ Delorie , eliz AT is DOT elta DOT co DOT il, blizzar AT hem1 DOT passagen DOT se, djgpp AT delorie DOT com, djgpp-workers AT delorie DOT com Date: Thu, 26 Mar 1998 14:14:59 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: NULL redefined! :( In-reply-to: <199803252351.SAA09923@delorie.com> References: (salvador AT inti DOT gov DOT ar) Precedence: bulk DJ Delorie wrote: > > > 2) Is equivalent to 0, that's: > > > > a) char *foo=0; then (foo==0) is true. > > BUT these are not equivalent: > > __null = foo; > 0 == foo; > > Also, looking up the value of a variable takes more CPU time than > comparing to a constant, and the compiler can't optimize it as well. It seems that you got it very wrong DJ: 1) You can't do __null=anything; as you can't do int=anything; 2) __null is solved in compile time, it isn't a variable is an special kind of constant. That's why you can pass it to C code. Take a look at this: ---- pp.cc: -------- #include int main(int argc, char *argv[]) { char *f=__null; printf("%d\n",f); return 0; } ----------------- gcc -S pp.cc ------- pp.s: -------- .file "pp.cc" gcc2_compiled.: ___gnu_compiled_cplusplus: .text LC0: .ascii "%d\12\0" .p2align 2 .globl _main _main: LFB1: pushl %ebp LCFI0: movl %esp,%ebp LCFI1: subl $4,%esp LCFI2: movl $0,-4(%ebp) <<<<<<<<<<<<< Here: gcc just put a 0, no optimizations used movl -4(%ebp),%eax pushl %eax LCFI3: pushl $LC0 LCFI4: call _printf addl $8,%esp LCFI5: xorl %eax,%eax jmp L1 .align 2,0x90 xorl %eax,%eax jmp L1 .align 2,0x90 L1: leave ret LFE1: [snipped] ----------------------- As you can see that's just a trick, as I told before I didn't have the time to see what advantage have, but the GNU C++ library of 2.8.x uses it and not the 0. SET ------------------------------------ 0 -------------------------------- Visit my home page: http://set-soft.home.ml.org/ or http://www.geocities.com/SiliconValley/Vista/6552/ Salvador Eduardo Tropea (SET). (Electronics Engineer) Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org CQ: 2951574 Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013