Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #136751

Re: Unwanted, implicit type conversion to a pointer when a value is zero?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Unwanted, implicit type conversion to a pointer when a value is zero?
Date 2018-10-13 11:36 -0700
Organization None to speak of
Message-ID <ln36t9wv5w.fsf@kst-u.example.com> (permalink)
References <eaf12c90-58a9-4a8f-b12f-4c0f79a50c59@googlegroups.com> <ppsisu$e0k$1@dont-email.me>

Show all headers | View raw


David Brown <david.brown@hesbynett.no> writes:
[...]
> Yes.  The integer constant 0 is a "null pointer" in C.  (Note that this 
> is /not/ the same as an int variable that happens to be 0!)  It is 
> usable as a pointer of any time, usually to indicate an invalid pointer 
> value.

The integer constant 0 is a *null pointer constant*, not a *null
pointer*.

A null pointer constant is a syntactic entity that exists in source
code.  A null pointer is a value that exists as a program is running.

A null pointer constant may be implicitly converted to a pointer
type, but the constant 0 is still of type int.

(I think somebody else already posted the standard's definition of
"null pointer constant".)

Note that this implicit conversion does not happen in all cases.
For example, this:
    printf("%p\n", 0);
does not convert the 0 to void*, and therefore has undefined behavior.

[...]

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Unwanted, implicit type conversion to a pointer when a value is zero? jladasky@itu.edu - 2018-10-12 17:12 -0700
  Re: Unwanted, implicit type conversion to a pointer when a value is zero? David Brown <david.brown@hesbynett.no> - 2018-10-13 12:54 +0200
    Re: Unwanted, implicit type conversion to a pointer when a value is zero? Keith Thompson <kst-u@mib.org> - 2018-10-13 11:36 -0700
  Re: Unwanted, implicit type conversion to a pointer when a value is zero? Bart <bc@freeuk.com> - 2018-10-13 15:19 +0100
    Re: Unwanted, implicit type conversion to a pointer when a value is zero? Keith Thompson <kst-u@mib.org> - 2018-10-13 11:37 -0700
      Re: Unwanted, implicit type conversion to a pointer when a value is zero? Bart <bc@freeuk.com> - 2018-10-13 20:21 +0100
        Re: Unwanted, implicit type conversion to a pointer when a value is zero? Keith Thompson <kst-u@mib.org> - 2018-10-13 12:57 -0700

csiph-web