Re: segfault on strtok

From: Al Bowers (xabowers_at_rapidsys.com)
Date: 10/24/03


Date: Fri, 24 Oct 2003 09:22:40 -0400


Andreas Kahari wrote:
> In article <3F9912C6.1399@mindspring.com>, pete wrote:
>
>>Andreas Kahari wrote:
>>
>>
>>>Yes, the integer zero is a null pointer, but only if it's cast
>>>to void * and converted into a pointer type.
>>
>>A constant expression with a value of zero,
>>is called a "null pointer constant"
>>(you can find that phrase in the standard),
>>whther or not it's cast to (void*).
>
>
> I was looking at the standard when I wrote it. It says that an
> integer which is zero is a null pointer constant if cast to void *.
> That null pointer constant is a null pointer if converted to
> a pointer type.
>

I believe what you are referring to in the standard is the
section 6.3.2.3 Pointers.
Paragraph:
3. An integer constant expression with the value 0, or such an
    expression cast to type void *, is called a null pointer constant.

Notice the word "or". It does not say "only if cast".
Among other posibilities, NULL may be defined as:
0, 0L, 0LL, or (void *)0.

---
Al Bowers
Tampa, Fl USA
mailto: xabowers@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/


Relevant Pages

  • Re: Ike Naar
    ... The issue is in the wording of the standard. ... expression compares equal to zero". ... pointer constant, but make no such statement for if. ... Why write "0" in English? ...
    (comp.lang.c)
  • Re: segfault on strtok
    ... > integer which is zero is a null pointer constant if cast to void *. ... > a pointer type. ... An integer constant expression with the value 0, ...
    (comp.lang.c)
  • Re: NULL with representation other then all bits 0
    ... > The NULL macro must expand to a null pointer constant. ... I think the C Standard defines "constant expressions" a bit before null ... doesn't have a value of zero. ...
    (comp.lang.c)
  • Re: Compiler error or? Microsoft VC++ v6.0
    ... The rule says that a null pointer constant is a ... > constant expression evaluating to zero. ... > constant qualifies as a constant expression. ...
    (microsoft.public.vc.language)
  • Re: What is a null pointer constant?
    ... Using this information google can bring it, ... >> defined in this International Standard are not to be presumed to ... it is the definition for the term, "null pointer constant," and also ... >> macro, not directly to the NULL macro. ...
    (comp.std.c)