envp[i]!=(char *)0

R

Rookie

If he did, he'd be wrong. 0 is a null pointer constant; (void *)0 is a
null pointer constant; but (char *)0 is _not_ a null pointer constant.
It's a null pointer constant, 0, _plus_ a cast to char *. This evaluates
to a null pointer with char pointer type, so it could be said to be a
null pointer, but it is not a null pointer constant.

Newbie question: Whats the difference between a null pointer and a null
pointer constant?
 
B

Ben Pfaff

Rookie said:
Newbie question: Whats the difference between a null pointer and a null
pointer constant?

Here are the official definitions from C99:

3 An integer constant expression with the value 0, or such an
expression cast to type void *, is called a null pointer
constant.55) If a null pointer constant is converted to a
pointer type, the resulting pointer, called a null pointer,
is guaranteed to compare unequal to a pointer to any object
or function.

Basically, a null pointer constant is a specific kind of
expression. If you then use it as a pointer, then it's a null
pointer.
 
K

Keith Thompson

Rookie said:
Newbie question: Whats the difference between a null pointer and a null
pointer constant?

The C FAQ is at <http://www.eskimo.com/~scs/C-faq/faq.html>.

Read section 5, "Null Pointers". (Then read the rest of the FAQ.)

Quick answer: a null pointer is a value that exists while your program
is running; a null pointer constant is a construct in your C source
program (that can indicate a null pointer value when it's evaluated).
 
M

Mark F. Haigh

Rookie said:
Newbie question: Whats the difference between a null pointer and a null
pointer constant?

Quoth the C99 standard:

6.3.2.3 Pointers

[...]

3. An integer constant expression with the value 0, or such an
expression cast to type void *, is called a null pointer constant.48)
If a null pointer constant is converted to a pointer type, the
resulting pointer, called a null pointer, is guaranteed to compare
unequal to a pointer to any object or function.


Mark F. Haigh
(e-mail address removed)
 
R

Richard Bos

Rookie said:
Newbie question: Whats the difference between a null pointer and a null
pointer constant?

Basically, the same difference as that between a float object with the
value 4.0 when your program is running, and the characters 4.0f in your
source code.

Richard
 

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,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top