D
Dan Pop
In said:Yeah yeah, alright.
I wonder what they mean by "or such an expression" though...
The obvious: both 0 and (void *)0 are null pointer constants.
Dan
In said:Yeah yeah, alright.
I wonder what they mean by "or such an expression" though...
Andreas said:On Fri, 24 Oct 2003 12:55:34 +0000, Andreas Kahari wrote:
[cut]
That's the draft standard. I have the book version of the
current standard, but it's at home at the moment. I'll have
to get back to this issue later tonight if noone else has the
current standard at hand and can verify this.
ISO/IEC 9899:1999
6.3.2.3 Pointers
3 An integer constant expression with the value 0, or such an
expressioncast to type void *, is called a null pointer
constant.
Yeah yeah, alright.
I wonder what they mean by "or such an expression" though...
ok .. i added the both include-lines, changed#include <stdio.h>
#include said:int main() {
char name[15];
strcpy (name, "ab8bc8cd8ed");
char cur[800];
strcpy (cur, strtok(name, "8"));
while (cur) {
cur is never going to be zero.
printf ("Output: %s\n", cur);
printf ("Stringlength %i\n", strlen(cur));
strcpy(cur,strtok(0, "8"));
(strictly speaking, the zero on that line should be a null
pointer)
printf ("next\n");
}
}
Check the return value of strtok(). It returns NULL when no
more tokens remains. NULL is defined in <stdlib.h>.
while (cur) {
in
while (cur != NULL) {
and replaced 0 with NULL in subsequenced strtok-func, but it keeps
producing segfaults :-(
I think, the problem causes when while run last time and strtok returns
NULL. Is there anything wrong with strcpy-ing this NULL pointer to var
"cur" ? (see also the output-wrap in first msg of thread)
0 converted to a pointer *is* a null pointer. There's nothing wrong with
using 0 here.
That is a matter of opinion.
But sensible. Why call a it an earth inverting horticultural
implement, when you can deobfuscate your code quite easily by using
handy macros that the Standard supplies?
As a matter of fact I usually do use "NULL", but I don't
find "0" to be any more obscure.
The token "0", consisting of one character, is hardly a fitting
counterpart to "earth inverting horticultural implement".
*shrug*. For me, I find it counterintuitive to say "if pointer is
zero" when I mean "if pointer is a null pointer", since pointers
aren't numbers, they're pointers.
Frankly when I see someone comparing a pointer to zero, the first
thing that crosses my mind is "does this guy realise that pointers are
not integers?
Sheldon said:It seems like you don't really "get" the fact that
...
char * p;
...
if (p == 0)
...
means exactly "if p is a null pointer" and not "if p is zero"
Since every conforming implementation must interpret every
integer constant expression with the value zero in a pointer
context as a null pointer constant, your feelings are misplaced.
It seems like you don't really "get" the fact that
Since every conforming implementation must interpret every
integer constant expression with the value zero
in a pointer context as a null pointer constant,
your feelings are misplaced.
Since
- NULL cannot possibly be defined any other way than as an
integer constant expression with the value zero (possibly
cast to void *), and
- every conforming implementation must interpret every integer
constant expression with the value zero that occurs in a
pointer context as a null pointer constant,
your feelings are misplaced.
I "get" it perfectly. Its just that zero is an integer, and letting
the compiler implicitly convert it to a void* so that you can compare
to a pointer, while syntactically fine, doesn't sit well with me.
Anyway, YMMV
HAND, OAO.
The compiler does the same thing whether or not you use the NULL
macro:
Mark said:You miss the point. This is nothing to do with the compiler. The
compiler probably also recognises
int* p = ((long)100000 - (long)pow(10,5));
as meaning "set p to a null pointer"
You miss the point. This is nothing to do with the compiler.
I doubt it. That doesn't look much an integer constant expression.
Then why did you mention it?
I didn't mention the compiler, you brought that up.
Shall we continue to psephologise?
Restoring Context...
No I didn't. You said that letting the compiler do a conversion
"doesn't sit well with you".
I just pointed out
Well since we aren't psephologizing (if there is such a word),
we can't continue. Why would we want to study elections in
comp.lang.c anyway?
Mark McIntyre said:Sheldon Simms <[email protected]> wrote:
yada yada. Nobody's listening to us.
<snip>Perhaps filibustering is closer to the mark.
Not true, it's kind of amusing. ;-)
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.