Xref: utzoo comp.arch:4773 comp.lang.c:10069 Newsgroups: comp.arch,comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: negative addresses Message-ID: <1988May12.162906.16901@utzoo.uucp> Organization: U of Toronto Zoology References: <2393@uvacs.CS.VIRGINIA.EDU>, <21541@amdcad.AMD.COM> Date: Thu, 12 May 88 16:29:06 GMT > Your program's virtual address space probably starts at -2**31, > rather than 0 (to give you the full range). This means that C-language > null pointers, because they are defined never to point to a valid > address, will probably have to be something other than the standard > all-zero bit representation. This is not a real problem... Unfortunately, it is a real problem, because there are zillions of programs that implicitly assume that pointers are all-zeros. It is true that the language does not require it, but doing anything else is an enormous pain in practice, according to the people who have experimented with the idea. Fortunately the problem can be bypassed, because there is absolutely no reason why the null pointer has to point to the beginning of your address space. It is sufficient for the machine and the memory allocator to conspire to ensure that no user data is ever allocated at location 0. This would qualify as a nuisance, but hardly a disaster. > ... it complicates the compiler somewhat (having to detect > the assignment/comparison of a pointer and the integer constant 0 as a > special case)... Not by much. Some machines already need such complications because their pointers and integers are not the same size. > ... uninitialized static pointers might break in horrible ways (this > is not necessarily bad! ;-) Are you going to fix all the programs that rely on it? ;-) More to the point, this is not an issue, because uninitialized static variables are *not* initialized to all-zeros, they are initialized to the zero value of their data type, which means the null pointer for pointers. Now this would be a bit of a pain for compilers on machines with odd representations of the null pointer. -- NASA is to spaceflight as | Henry Spencer @ U of Toronto Zoology the Post Office is to mail. | {ihnp4,decvax,uunet!mnetor}!utzoo!henry