Pointer Guide Nearing Completion

  • Thread starter Foobarius Frobinium
  • Start date
M

Michael Mair

Foobarius said:
That's unusual...it disagrees with 5.10 in C FAQ, which says NULL is a
stylistic convention, and guarantees 0's to be null pointers.
^^^^^^^^^^^^^^^^^^^^^^^

What Richard probably is referring to is the fact that neither
NULL nor 0 are _pointers_ but are interpreted as a null pointer
constant. 0, as it is, is an integer value. If this is converted into a
pointer, anything can happen to the actual value of the pointer.

That means
int i, ptr=NULL;
unsigned char *rep;

rep=&ptr;
for (i=0; i<sizeof ptr; i++)
printf("%x\n",(unsigned int) (*rep++));
will not necessarily give you
0x0
0x0
....

So, what I marked above, is *wrong*.
Just out of curiousity, why would NULL be defined as 48?

NULL is never defined as 48 but the actual representation of
a "pointer that does not point anywhere" is not necessarily 0.
If it is a valid address that is during runtime interpreted
as null pointer, it is not necessarily "byte zero" or "segment:eek:ffset
with offset 0".


Cheers
Michael
 
O

Old Wolf

Even that is bunkum. NULL isn't a pointer.

Argh.
"A null pointer is a pointer that doesn't point anywhere."
"NULL is a null pointer constant."
"When a null pointer constant is converted to a pointer type,
the result is a null pointer."
Happy?
The most likely value of NULL is 48.

I don't see how NULL can have a value of 48.
 
M

Mabden

Old Wolf said:
Argh.
"A null pointer is a pointer that doesn't point anywhere."
"NULL is a null pointer constant."
"When a null pointer constant is converted to a pointer type,
the result is a null pointer."
Happy?


I don't see how NULL can have a value of 48.

Couldn't a pointer to a zero that is called NULL reside at address 48 in
memory, thereby making NULL have a "value" of 48? ;-) Just asking...
 
M

Michael Wojcik

I don't see how NULL can have a value of 48.

One of the permissible values of the NULL macro is 0 - a character
from the source character set. NULL is expanded during translation
phase 4. Its immediate value, then, is not binary 0, but some
sequence of pp- tokens in the source character set. If the source
character set happens to be ASCII, or to use the same code point as
ASCII for the '0' character, and NULL is defined simply as that
character, then in a sense the "value" of NULL is a single char with
binary value 48 (the code point of '0' in ASCII).

If you hypothesize, then, that a majority of implementations use
ASCII and define NULL as 0, you might say the value of NULL is 48.

Or you might not. Clearly NULL has various "values" at various
stages of translation, and in various conceptual domains, and I don't
see a strong argument for declaring any of them the "real value" of
NULL.

It was a clever bit on Richard's part, though.

--
Michael Wojcik (e-mail address removed)

Pseudoscientific Nonsense Quote o' the Day:
From the scientific standpoint, until these energies are directly
sensed by the evolving perceptions of the individual, via the right
brain, inner-conscious, intuitive faculties, scientists will never
grasp the true workings of the universe's ubiquitous computer system.
-- Noel Huntley
 
R

Richard Bos

One of the permissible values of the NULL macro is 0 - a character
from the source character set. NULL is expanded during translation
phase 4. Its immediate value, then, is not binary 0, but some
sequence of pp- tokens in the source character set. If the source
character set happens to be ASCII, or to use the same code point as
ASCII for the '0' character, and NULL is defined simply as that
character, then in a sense the "value" of NULL is a single char with
binary value 48 (the code point of '0' in ASCII).

If you hypothesize, then, that a majority of implementations use
ASCII and define NULL as 0, you might say the value of NULL is 48.
Bingo.

Or you might not. Clearly NULL has various "values" at various
stages of translation, and in various conceptual domains, and I don't
see a strong argument for declaring any of them the "real value" of
NULL.

True, but my main point was that NULL is not a pointer, neither a
pointer object nor a pointer value, but a macro. A bit of text in your
source code. Null pointers point at no object; a null pointer constant
does not point. Confusion between null pointers and null pointer
constants is probably the greatest cause of problems people have with
null pointers.

Richard
 
M

Michael Wojcik

True, but my main point was that NULL is not a pointer, neither a
pointer object nor a pointer value, but a macro. A bit of text in your
source code. Null pointers point at no object; a null pointer constant
does not point. Confusion between null pointers and null pointer
constants is probably the greatest cause of problems people have with
null pointers.

Oh, I agree, which is one of the reasons why I called it a clever
bit. Certainly it'd be a way for newbies to remember the differences
among NULL, null pointer constants, and null pointers. If they say
to themselves "a common value for NULL is 48", then take a moment to
remember in what context that's true, that would probably make a fine
mnemonic device for the whole concept.

--
Michael Wojcik (e-mail address removed)

Although he was an outsider, and excluded from their rites, they were
always particularly charming to him at this time; he and his household
received small courtesies and presents, just because he was outside.
-- E M Forster
 
M

Mike Wahler

Mabden said:
Couldn't a pointer to a zero that is called NULL reside at address 48 in
memory, thereby making NULL have a "value" of 48? ;-) Just asking...

The value of a pointer and the value of the object to which
it points (if any), are distinct.

int i = 42; /* the value of 'i' is 42 */
int *p = &i; /* the value of 'p' is *NOT* 42 */
/* the value of 'p' is the memory address of 'i' */

The value of NULL is zero, or zero converted to type 'void*'.
The value of a pointer object after having NULL assigned to it is
"null pointer". This might or might not corresponding to a bit
pattern of all zeros, or the binary value of 48, or ... etc.

-Mike
 
M

Mabden

Mike Wahler said:
The value of a pointer and the value of the object to which
it points (if any), are distinct.

int i = 42; /* the value of 'i' is 42 */
int *p = &i; /* the value of 'p' is *NOT* 42 */
/* the value of 'p' is the memory address of 'i' */

The value of NULL is zero, or zero converted to type 'void*'.
The value of a pointer object after having NULL assigned to it is
"null pointer". This might or might not corresponding to a bit
pattern of all zeros, or the binary value of 48, or ... etc.

You didn't answer the question.
In your example, couldn't the value of 'p', which is the memory address
of 'i', be 48 if that is where 'i' resides (where the 42 is)?
 
B

Blue River

Mike said:
The value of a pointer and the value of the object to which
it points (if any), are distinct.

int i = 42; /* the value of 'i' is 42 */
int *p = &i; /* the value of 'p' is *NOT* 42 */
/* the value of 'p' is the memory address of 'i' */

The value of NULL is zero, or zero converted to type 'void*'.
The value of a pointer object after having NULL assigned to it is
"null pointer". This might or might not corresponding to a bit
pattern of all zeros, or the binary value of 48, or ... etc.

The idea is that it points to a special memory zone, unaccesible to
the program, so it is not sure is the address it contains is 0 or x != 0

mailto: (e-mail address removed)
mailto: (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,373
Latest member
Desiree036

Latest Threads

Top