Copying string till newline

S

Seebs

Hence, (1) NULL is a macro defined in one of the std lib headers

(2) null pointer is equal to the null pointer constant.

At least, it compares equal.
(3) And from C-FAQ 5.1 and 5.9, I see null pointer constant is just a 0
(zero). zero and null pointer are equal (in the case of pointers only).

Not exactly. The key is that a *constant* zero, converted to a pointer,
is guaranteed to be a null pointer.

Consider:
int *p = 0;
int i = 0;
if (((int *) i) != p) {
/* this CAN happen */
}

There aren't all that many systems where the if control expression will
evaluate to true, but they do exist.
(4) null character is '\0' which is not equal to the null pointer.

Almost right. It turns out that '\0' is, in fact, an integer constant
with the value 0, so it is a valid null pointer constant, and if
converted to a pointer type, yields a null pointer.
am I right now ?
Sorta.

Now I know NULL, null pointer, null pointer constant and null character.
What is nul (with single l) that you are talking about ?

Not nul, NUL. The ASCII character set defines a number of characters
with values from 0 through 31 which have special meanings. Character
zero is NUL. (The first few are NUL, SOH, STX, ETX, EOT, ENQ, ACK,
BEL...)

-s
 
B

Barry Schwarz

where above are better than
0 0x00000000
(void*)0 0x00000000
(int*) 0 0x00000000

are for help the compiler?

Better, like beauty, is in the eye of whoever is developing the
implementation.

There are reasons why a null pointer of all bits zero is convenient.
It obviously simplifies the code to be generated for something like
char *p = 0;

There are also reasons why it is not. For example, on my system,
address 0 is universally available to all tasks for reading only.
Therefore
char x = *(char*)0;
should not be prohibited while
*(char*)0 = '1';
should be limited to operating system tasks.
 

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

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,114
Members
46,702
Latest member
VernitaGow

Latest Threads

Top