On Monday, January 6, 2003, at 10:37 PM, Greg Hudson wrote:
> On Mon, 2003-01-06 at 19:11, Philip Martin wrote:
>> John Barstow <John_Barstow@gfsg.co.nz> writes:
>>> 1) Pointers are not initialized to NULL. This may not matter too
>>> much on
>>> Unix, but on Windows, uninitialized pointers point to random
>>> locations in
>>> memory. This makes debugging very painful and bugs very
>>> unpredictable -
>>> especially since the problem is less pronounced in debug mode.
>
>> Not sure why you say this affects Windows more than Unix.
>
> In Unix, an uninitialized pointer might, conceivably, scribble over
> memory owned by the current application. But it's much more likely to
> cause a bus error or segmentation fault. In Windows, as I understand
> the argument, an unintialized pointer might scribble over memory owned
> by another application, or by the OS.
Okay, i hate to point it out, because i figured someone would already,
but it *does* affect unix more than windows. At least, if you are
talking about linux.
On Linux , uninitialized data is placed in the .bss section.
You are *guaranteed* that uninitialized data will be 0 (if it is put in
the .bss section) on linux.
Why?
The .bss section takes up no file space.
Since the data isn't initialized, to save file space, the actual *data*
(which would be zeroes or random values anyway) is omitted, and when
the image is loaded by the OS, it's zero filled.
I know at least a few other ELF based unix systems do this, i can't
remember if it's ABI specified in those cases, or just common.
.bss exists on Windows as well, but i'm not sure it's zeroed out on
load. In fact, IIRC, most linkers merge it with the end of the
initialized data section so that no mapping of memory is necessary when
the pointer is accessed. It just gets the value of some piece of
initialized data.
Some OS'en do even cuter things in regard to null pointers.
On AIX, for instance, memory address 0 is mapped so that dereferencing
a NULL pointer gives you the value 0, rather than segfaulting. The
*real* reason for this isn't to avoid the segfault, it's so it can omit
null pointer checks and lift loads guarded by null conditions (IE a = b
!= NULL ? b : 0), since the result will be the same.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Jan 7 07:00:28 2003