Re: "PORTING C" > NULL problem!
Pavel A. <pavel_a@12fastmail34.fm> wrote:
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:ue#16NcqKHA.4492@TK2MSFTNGP05.phx.gbl...
A null pointer doesn't point to any valid location, which naturally
can't contain any particular value. Just try it:
int* p = NULL;
int x = *p; // see what happens.
There may be a real memory location with adress 0
Not on Windows.
so dereferencing "null pointer" may be possible physically -
especially on small microcontrollers like what the OP struggles
against.
That's why I said "architecture-dependent" and "on most machines".
I remember x86 under DOS (real addressing mode, no funny virtual memory =
business) had its interrupt table at address 0 and up. Writing through a =
NULL pointer had rather interesting consequences - suddenly, a random =
memory address became the entry point for some interrupt handler. =
Single-step debugging was implemented via INT 1, so if you managed to =
overwrite that, you would disable your debugger, too. Good times.
.NET has a special nullptr keyword, instead of this controversal
0/NULL thing.
C++0x has this, too, but also, inevitably, supports 0 and NULL for =
backward compatibility. VS2010 (coming Real Soon Now) implements various =
parts of C++0x, including nullptr if I recall correctly.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not =
necessarily a good idea. It is hard to be sure where they are going to =
land, and it could be dangerous sitting under them as they fly overhead. =
-- RFC 1925