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


Groups > comp.std.c > #1776

Re: null pointer constant, address constant

From Tim Rentsch <txr@alumni.caltech.edu>
Newsgroups comp.std.c
Subject Re: null pointer constant, address constant
Date 2012-12-20 21:13 -0800
Organization A noiseless patient Spider
Message-ID <kfnhang7ztr.fsf@x-alumni2.alumni.caltech.edu> (permalink)
References (3 earlier) <kaqmd8$u9m$1@dont-email.me> <lnzk1ark9h.fsf@nuthaus.mib.org> <89afe21d-1a8b-4749-8ad1-ec98cc65a818@a8g2000vby.googlegroups.com> <kavb4b$ed2$1@dont-email.me> <50D34AC9.4040907@verizon.net>

Show all headers | View raw


James Kuyper <jameskuyper@verizon.net> writes:

> On 12/20/2012 10:33 AM, James Kuyper wrote:
>> On 12/20/2012 08:34 AM, christian.bau wrote:
>>> On Dec 18, 11:52 pm, Keith Thompson <ks...@mib.org> wrote:
>>>
>>>> The standard says that a constant arithmetic expression with the value
>>>> 0, converted to a pointer type, yields a null pointer.  It does *not*
>>>> say the same thing about a non-constant arithmetic expression with the
>>>> value 0.
>>>
>>> It doesn't have to. The standard doesn't have to state something
>>> explicitly if it follows from other rules that are stated.
>>>
>>> Converting _any_ integer to _any_ pointer gives an implementation-
>>> defined result.
>> 
>> Not so. "An integer may be converted to any pointer type. Except as
>> previously specified, the result is implementation-defined, ..."
>> 6.3.2.3p5. Since null pointer constants are described in 6.3.2.3p4, they
>> are covered by "Except as previously specified". Conversion of
>> non-constant arithmetic expressions with a value of 0 is NOT covered by
>> that exception. This means that the implementation-defined result of
>> such a conversion need not match the standard-defined result for null
>> pointer constants.
>
> After thinking about it a little while, I realized I hadn't worded
> that quite right, and that my citation was incorrect.  Here's a
> corrected version:
>
> Since null pointers are described in 6.3.2.3p3, they are covered by
> "Except as previously specified".  Conversions of integer
> expressions with a value of 0 to pointer types which are not covered
> by 6.3.2.3p3 are therefore not covered by that exception, and need
> not be defined by the implementation to produce the same result.
>
> I think that you're assuming that there's some kind of consistency
> requirement imposed by the standard on the implementation's
> definition of the result.  For instance, that it is determined
> solely by the integer's value and the type of the pointer.  The
> standard imposes no such requirement.  The result could depend upon
> the type of the integer.  It could depend upon the kind of
> expression used to produce that integer.  It could depend upon the
> phase of the moon, and whether or not today is Friday the 13th.  It
> could be completely random.  I can't come up with a good reason for
> any of those things to be true, but it would not render the
> implementation non-conforming if they were.
>
> If there were such a consistency requirement, it would depend upon
> the precise wording of that requirement whether or not it requires
> consistency between the result, when it's implementation-defined,
> and the result when the implementation has no obligation to provide
> a definition, because it's standard-defined (by 6.3.2.3p3).
> However, that issue doesn't come up, because there is no such
> consistency requirement.

Longer, but still begging the same question.  The text of the
Standard does not produce this conclusion clearly enough.  At
the very least a clarifying footnote is needed.

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


Thread

null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-18 13:25 +0000
  Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-18 09:53 -0500
    Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-18 20:06 +0000
      Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-18 15:39 -0500
        Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-19 00:44 +0000
          Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-18 20:24 -0500
            Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-19 10:27 +0000
              Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-19 07:15 -0500
              Re: null pointer constant, address constant Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-12-21 03:03 +0200
                Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-21 12:13 -0500
                Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2013-01-09 00:44 +0000
                Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2013-01-08 20:21 -0500
                Re: null pointer constant, address constant Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-08 20:46 -0500
          Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 20:37 -0500
      Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 16:15 -0500
        Re: null pointer constant, address constant Keith Thompson <kst-u@mib.org> - 2012-12-18 15:52 -0800
          Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 19:12 -0500
            Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 19:51 -0500
          Re: null pointer constant, address constant Keith Thompson <kst-u@mib.org> - 2012-12-18 17:02 -0800
          Re: null pointer constant, address constant "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-12-20 05:34 -0800
            Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-20 10:33 -0500
              Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-20 12:28 -0500
                Re: null pointer constant, address constant Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 21:13 -0800
              Re: null pointer constant, address constant Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 21:05 -0800
            Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-20 12:17 -0500
            Re: null pointer constant, address constant Keith Thompson <kst-u@mib.org> - 2012-12-20 12:10 -0800
              Re: null pointer constant, address constant Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 21:25 -0800
  Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 14:02 -0500
    Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-18 20:09 +0000
      Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-18 15:54 -0500
        Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 16:18 -0500

csiph-web