Have you ever noticed that people use zero in there programming in very strange ways? 0, NULL and ''\0'' are all zero... but when was the last time you saw somebody write memset(&something, ''\0'', sizeof(something))? Or how about pSomething = ''\0''? It isn''t exactlly common to go around setting char array members to NULL either. They all mean the same thing, but they are all used differently.
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
NULL 0x000000... refers to memory space literal 0x00000... That''s the whole idea... that a pointer points to the literal zero "chunk" of your memory space. Now, we happen to define NULL as 0x000... in memory space, because that''s what our machines do... but... it would be perfectly valid for the designers to have decided that 0xFFFFFF... is their definition of NULL. Or 0xCDCD... or anything else... the important thing is that it''s recognized as the defined "NULL" for the system.
0x0000... as a numerically defined zero has no real bearing on memory space. It''s not a pointer (well, it could be if you''re doing odd casting stuff, but realistically it''s generally not), it''s merely that 0x0000... is the literal hex value for zero. You actually missed one here, because the hex ascii value for zero happens to be 0x30.
Similar to the notion of a pointer, ''\0'' happens to be the chosen definition of the termination character. It is zero only by virtue of the fact that that happens to be the defined value for a terminating character (and NULL, for that matter... though really, the string termination character doesn''t necessarily have to be defined the same as NULL, if the designers decide they don''t want it to be. They probably did it to make it a bit easier, but... they didn''t have to.)
Utterly confused yet? *grin*
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
felisandria''s correct in that its all a matter of context.
I actually think its quite unfortunate that ''\0'' == NULL == 0 because it results in some sloppy code whereby sometimes even the same programmer will use these different constructs inconsistently or incorrectly (terminating a string with NULL, etc).
Its interesting to note that in C++ it is often advocated that 0 be used to represent the NULL-pointer rather than the NULL define. The standard calls for ''new 0'', not NULL, to be returned in cases of error (such as memory allocation failure).
In C++, unlike in older versions of standard C, NULL always has to be 0 (or (void *)0). If a system uses some other pattern to represent the null pointer internally, its the job of the compiler (not the preprocessor) to deal with that translation from 0 to whatever.
? I fail to see the reasoning there. By telling it 45, you are asking for the ascii character defined by the number 45 decimal to be printed (which, by the way, happens to be a dash... reference your ascii chart codes. You are allowed to refer to ascii characters by hex value, decimal value, or character itself, which is pretty nifty when you''re doing assembly). The ''\0'' is processed internally to printf, not by virtue of ''\0'' happening to be zero literal.
It''s already been demonstrated that 0 ascii != 0 literal, so 0 doesn''t equal \0, in character terms.
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
fels right. It is only in some stupid languages that you cant do that and you have to go through a few conversion routines. Be glad that C/C++ allows it
I think you missed my point. I wasn''t saying that they had to be zero... they could be 18927 for all I care. I was just commenting on how they all DO usually mean the same thing, but people generally use them differently (and correctly, but still...).
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
But they don''t mean the same thing. They just happen to be represented the same way.
NULL means uninitialized pointer 0 means the value of 0 ''\0'' means the character that has the acsii code of 0 (which is the string terminator in C&C++)
\0 exist so its easy to terminate strings in C, just like \n means 0x1310
...
The C++ standard discards the use of NULL in favor of 0 for uninitialzed pointers, but many coders (myself included) fail to see the logic of this and continue to NULL. 0x0 would have made more sense (to me) than 0 for pointers...
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
"people generally use them differently (and correctly, but still...). "
That''s our point, Yanroy. The entire point we''re trying to make is that although the values may be the same, they do NOT mean the same thing.
Therefore, if you insist on using one and skipping the others, yes, it will work for now, but... if you ever meet a system that doesn''t say that the intrinsic value of NULL == literal 0 == \0, you''re in trouble. Your code will not work.
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Apparently you still didn''t get my message. I must have not worded it very well. We are all arguing the same side.... I know that they MEAN different things, but they all have the same value. I should have said that earlier. Maybe its time to give this thread a rest....
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor