Re: validity of a pointer
- From: Wolfgang Draxinger <wdraxinger@xxxxxxxxxxxxxxxx>
- Date: Tue, 27 Jan 2009 22:50:10 +0100
pete wrote:
Wolfgang Draxinger wrote:
First read the pointer FAQ. Then you must understand, that the
only "invalid" pointer in terms of C is the null pointer, with
the value 0.
An indeterminate pointer is more invalid than a null pointer.
In terms of C a null pointer is not something invalid in the term, that it
may not be there. However dereferencing a null pointer is invalid, thus I
wrote the word "invalid" in quotations marks, to designate it as being
meant in the OPs intention.
Any pointer with a value not being null can be dereferenced legally, as long
as we'te talking in terms of the language.
In terms of a specific implementation there might be further values, that
are invalid for a given pointer type (e.g. pointer values are alignment
constrained).
And then there is the classification of a pointer being valid or not by the
(operating system). Today one can cheaply build a 32 bits machine with 4GiB
memory (costs about 100$). Without a operating system, memory protection
and a paging system the physical memory can be addressed linearily. In this
situation, 32 bit CPU and 4GiB of memory running a single program in
physically addressing mode, virtually every pointer can be dereferenced
without raising a bus error exception.
But the C language deliberately doesn't specify anything about the low level
details that are implied by pointers. The only thing that's granted is,
that a pointer with the value 0 cannot be dereferenced and thus may be
considered invalid.
Wolfgang
P.S.: That I gave some detailed information on how to check a pointer for
validity under Linux is, that there's IMHO no sensible newsgroup for such
questions. The closest match would be comp.os.linux.development.apps, but
the guys there are focused on things like GUI and stuff like that. The
other Linux devel NG is comp.os.linux.development.system, which focuses on
the kernel and there a whole set of other rules apply.
.
- Follow-Ups:
- Re: validity of a pointer
- From: jameskuyper
- Re: validity of a pointer
- From: pete
- Re: validity of a pointer
- References:
- validity of a pointer
- From: sinbad
- Re: validity of a pointer
- From: Wolfgang Draxinger
- Re: validity of a pointer
- From: pete
- validity of a pointer
- Prev by Date: Re: Need clarity on structure alignment
- Next by Date: Re: WINSCP for Linux
- Previous by thread: Re: validity of a pointer
- Next by thread: Re: validity of a pointer
- Index(es):
Relevant Pages
|