Re: offsetof



darkknight wrote:
On Sat, 01 Oct 2005 01:20:28 +1200, darkknight wrote:

On Fri, 30 Sep 2005 13:27:44 +0100, Flash Gordon wrote:

darkknight wrote:

<snip stuff that seems about right>

The expression (type*)0 does NOT create a NULL pointer constant unless
the type of "type" is void  i.e. it is (void*)0.

Wrong. It explicitly IS a null pointer constant of the specified type. In fact, with (type*)0 the 0 is a null pointer constant and, at run time, it explicitly gives you a null pointer.

Please quote the relevant sections of the standard to support your claim.

Never mind. I found it. You are right.

There was me about to admit that whilst the 0 in the above is a null pointer constant, and you do get a null pointer of the specified type, you don't get a null pointer *constant* of the specified type. A subtle point perhaps, and not one that affects programming in practice, but possible valid. :-)
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.




Relevant Pages

  • Re: Definition of NULL
    ... you have a null pointer. ... use a null pointer constant in your source code whenever you want a null ... It can determine the same thing, btw, if NULL is defined as (void *)0, ... required type, or 0 cast to the required type. ...
    (comp.lang.c)
  • Re: system() without waiting
    ... should make it a null pointer of type T. ... An integral constant expression with value 0, or the same cast to ... The null pointer constant in C is a constant ... expression cast to type void *, is called a null pointer constant. ...
    (comp.unix.programmer)
  • Re: What is a null pointer constant?
    ... >>> pointer constant. ... > The purpose would be to avoid confusion and special-case rules. ... The semantics of control expressions ...
    (comp.std.c)
  • Re: NULL with representation other then all bits 0
    ... The standard's definition of a null pointer constant is: ... > is an lvalue, a function designator, or a void nexpression if the ... a primary expression is a conditional expression. ...
    (comp.lang.c)
  • Re: Difference between and NULL
    ... It is actually an "escape sequence" with an octal zero. ... The second is a macro that resolves to a null pointer value. ... NULL is a null pointer constant, ... or such a constant cast to void *. ...
    (comp.lang.c)