From: Igor Tandetnik on 9 Feb 2010 15:07 Robby <Robby(a)discussions.microsoft.com> wrote: > But, where is this "nowhere" ???? This is architecture-dependent. Usually a null pointer contains an invalid address (so that trying to dereference it would be caught by the CPU). On most machines, that would be an address of zero. On Windows, for example, lower 64K of address space are reserved and would trigger an access violation if you try to access any location there: this catches most cases where null pointers are misused. > "Between you and I, everything > points to something No, not really. There are plenty of addresses in the address space that are not dereferenceable - hence the existence of Access Violation. > if it points to a location conataining the value > of 0, then lets say it. It doesn't. 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. -- 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
From: Pavel A. on 9 Feb 2010 19:31 "Igor Tandetnik" <itandetnik(a)mvps.org> wrote in message news:ue#16NcqKHA.4492(a)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 (either code or data or both), so dereferencing "null pointer" may be possible physically - especially on small microcontrollers like what the OP struggles against. On most "normal" VM systems, both code and data null locations are excluded from virtual space of a process, so they cause exception. ..NET has a special nullptr keyword, instead of this controversal 0/NULL thing. Regards, --pa
From: Igor Tandetnik on 9 Feb 2010 19:52 Pavel A. <pavel_a(a)12fastmail34.fm> wrote: > "Igor Tandetnik" <itandetnik(a)mvps.org> wrote in message > news:ue#16NcqKHA.4492(a)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
From: Robby on 11 Feb 2010 09:34 "Igor Tandetnik" wrote: > Robby <Robby(a)discussions.microsoft.com> wrote: > > But, where is this "nowhere" ???? > > This is architecture-dependent. Usually a null pointer contains an invalid address (so that trying to dereference it would be caught by the CPU). On most machines, that would be an address of zero. On Windows, for example, lower 64K of address space are reserved and would trigger an access violation if you try to access any location there: this catches most cases where null pointers are misused. > > > "Between you and I, everything > > points to something > > No, not really. There are plenty of addresses in the address space that are not dereferenceable - hence the existence of Access Violation. > > > if it points to a location conataining the value > > of 0, then lets say it. > > It doesn't. 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. That's the under-the-hood explanation I was looking for. Igor, thankyou very much. Regards Roberto
From: Ulrich Eckhardt on 12 Feb 2010 03:05 Igor Tandetnik wrote: > Ulrich Eckhardt wrote: >> A void pointer doesn't have any type > > This is not true formally, and I don't think it's useful to think this way > informally either: 6.2.5p19 The void type comprises an empty set of > values; it is an incomplete type that cannot be completed. The type defines the behaviour of an instance, all instances of the same type share similar behaviour. Since void is incomplete, you can never have any instances of it. An empty set of values means pretty much the same, that it can't exist. In that context, calling void a placeholder for the lack of a type is a reasonable description to me. Agreed, it is not formally true, since the C standard uses a different meaning, but informally that description is useful. Uli -- C++ FAQ: http://parashift.com/c++-faq-lite Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Books on Shell and gadgets programming Next: StartupInfo in CreateProcess for ShowWindow |