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


Groups > comp.lang.c > #30439

Re: [union] Pointers to inherited structs are valid ?

From Shao Miller <sha0.miller@gmail.com>
Newsgroups comp.lang.c
Subject Re: [union] Pointers to inherited structs are valid ?
Date 2013-01-21 00:05 -0500
Organization A noiseless patient Spider
Message-ID <kdiibb$adj$1@dont-email.me> (permalink)
References (17 earlier) <ln1udf979x.fsf@nuthaus.mib.org> <kdhjs3$s8d$1@dont-email.me> <0.0b1231aec01398fe5573.20130120235839GMT.87libn76fk.fsf@bsb.me.uk> <kdi97a$32l$1@dont-email.me> <0.3967aeb7bf6a1530832e.20130121025322GMT.87fw1v6ycd.fsf@bsb.me.uk>

Show all headers | View raw


On 1/20/2013 21:53, Ben Bacarisse wrote:
> Shao Miller <sha0.miller@gmail.com> writes:
>
>> On 1/20/2013 18:58, Ben Bacarisse wrote:
>>> Shao Miller <sha0.miller@gmail.com> writes:
>>>
>>>> On 1/20/2013 10:57, Keith Thompson wrote:
>>>>> Shao Miller <sha0.miller@gmail.com> writes:
>>>>>>
>>>>>> Which of these most closely resembles the pointer value 0x0000000C in
>>>>>> this Windows scenario?:
>>>>>>
>>>>>>       1. A trap representation for some pointer type, invoking UB when read
>>>>>>       2. A valid value for some pointer type; pointing to an object
>>>>>>       3. A null pointer; pointing to no object, invoking UB when dereferenced
>>>>>>
>>>>>> If it doesn't compare equal to 'NULL', then it doesn't appear to match
>>>>>> any of these.  But if we can fuzz our way from Standard theory to
>>>>>> real-world practice, we might note some similarities to #3.
>>>>>
>>>>> It could easily be #1.  For example, if a type `struct foo` has a
>>>>> member `bar` at offset 12 (0xC), and a `struct foo*` object `ptr`
>>>>> that has a null pointer value, then `&(ptr->bar)` could easily have
>>>>> a representation that looks like 0x0000000C.
>>>>>
>>>>
>>>> It could be #1, but it isn't #1 in this Windows scenario.  Using such
>>>> a pointer value doesn't yield undefined behaviour until it's
>>>> dereferenced. It'll still compare as unequal with valid pointer
>>>> values, can still be assigned to a pointer, etc.
>>>
>>> All of that seems to be entirely consistent with #1.
>>
>> I made the mistake of saying "undefined behaviour" there, instead of
>> "unexpected behaviour."  My point was that the unexpected only
>> manifests from a _dereference_, rather than a _read_.
>
> How far back?

Probably 12 posts back from this one I'm typing now; sorry.

> In how many posts must I substitute "unexpected
> behaviour" for "undefined behaviour" in order to determine your meaning?

5 of mine; sorry.

> Have you said what "unexpected behaviour" is?

Not explicitly, no.  I thought it would be obvious that it was the 
context of a Windows debugger notifying the programmer, since Geoff had 
just discussed that.

> Does it depend on who is
> doing the expecting?

Not really.  If the program operates as expected without the debugger 
interrupting, that's probably commonly desired by different programmers.

> Does any meaning survive after addressing these
> questions?
>

Yes, I think so.  Having seen these answers, do you? :)

>>> Talking about whether something is UB in "this Windows scenario" looks
>>> very odd to me because the term UB is defined by the language, not the
>>> implementation.  If the language says something is UB then it is and you
>>> can't conclude from the behaviour of an implementation that it isn't.
>>>
>>> <snip>
>>
>> Agreed, and it's supposed to be odd.  This discussion is pretty
>> useless though, because no matter how many times I try to suggest
>> considering "C definitions" versus "practiced usage," nobody quite
>> seems to; possibly because the latter is uninteresting to them, or
>> because this Windows case is uninteresting to them, or because I make
>> mistakes like the above without qualifying each term as "not to be
>> confused with the C definition".  I thought it would be an easy
>> discussion; it isn't.  My mistake.
>
> But you seem to make the same mistake when explicitly using C's terms
> and without any of the "unexpected/undefined" madness above.  E.g.:
>
> | For example, if a free'd pointer becomes 0x0000000C, in C terminology,
> | it'd be an "indeterminate value."  But, using C terminology again,
> | it'd be an "unspecified value" rather than a "trap representation", as
> | the value can be read and passed around.
>
> This suggest that you think it can't be a trap representation because it
> can be read and passed around.  A trap representation is nothing more
> than a representation that does not denote a valid value for the type
> in question.  The effect of using it can be entirely benign.
>

I'm sorry you interpreted it that way.  Would it be best to surround 
every paragraph of every response with context, to prevent 
misunderstanding?  In that quote, I thought it was obvious that this was 
in the context of using a Microsoft debugger, where the behaviour would 
agree with the semantics of an "unspecified value"; not warning the 
programmer during a read of the value (which it _could_).

In the summary below, I hope it's clear that a recurring theme was to 
establish 0x0000000C as some kind of a trap value, so the quote above 
doesn't match with that without deciding that it needs additional context.

Here's a summary of how the conversation has gone, from my perspective. 
  All quotes are fictional, and names have been omitted:

Me: "If an uninitialized 'unsigned char' can have a trap representation, 
then...[something]"

A: "Whatever it has isn't a trap representation, you idiot.  It might 
not even have a value."

Me: "Why wouldn't it have a value?  Is it because it might not 
successfully translate?  Ok, what about in this code example where it 
does translate?"

B: "What would you say it has?"

Me: "An [C] indeterminate value and a magic property \"uninitialized\". 
  Here's some history, since you asked what I would say..."

B: "Here are Microsoft's documented [non-C] trap values..."

Me: "Nice summary!  Say, isn't there another one, 0x0000000C, as a 
[non-C] trap for [non-C] null pointers?  I don't remember..."

C: "Oh no, that wouldn't be a [C] null pointer."

Me: "Yes, well I was talking about B's [non-C] trap values.  I see a 
Microsoft debugger catch these things and call them [non-C] null pointers."

C: "A [C] null pointer isn't a [C] trap representation.  Does this thing 
behave like a [C] null pointer?"

Me (intended): "Well it only behaves badly upon dereferencing."

C: "If it's not a [C] null pointer, then it shouldn't be called one, and 
it's off-topic."

D: "There could be multiple [C] null pointer representations."

Me (missing C's cue to drop it): "That could be.  Maybe the bits have 
something to do with useful debug-info, such as a 'free'd pointer."

C: "That seems unlikely, due to pass-by-value.  We're still not talking 
about [C] null pointers if it doesn't behave like a [C] null pointer."

Me: "Agreed; it doesn't match.  So what's the closest thing, 
behaviour-wise?  It seems like a [C] null pointer, in some ways."

C: "It could be closest to a [C] trap representation.  It seems pretty 
straight-forward."

Me (intended): "Well for those who observe 0x0000000C in a Microsoft 
debugger, the program behaves well until it's dereferenced, so it's not 
closest to a [C] trap representation, but to a [C] null pointer."

You: "It could be closest to a [C] trap representation.  And don't say 
\"undefined behavour\" if you don't mean it."

Me: "Oops.  True."

>> And agreed again; we all [ought to] know:
>>
>>> All behaviours are consistent with UB.
>>
>> Thankfully, 3 people have now made it abundantly clear that comparing
>> C terminology to subjects outside of C is not going to be fruitful. :)
>
> Are you not using C's terms in the quote above?
>

Yes I was, but it only makes for confusion, so I'll try to avoid that.

-- 
- Shao Miller
--
"Thank you for the kind words; those are the kind of words I like to hear.

Cheerily,"  -- Richard Harter

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


Thread

[union] Pointers to inherited structs are valid ? Maciej Labanowicz <m.labanowicz@gmail.com> - 2013-01-01 03:45 -0800
  Re: [union] Pointers to inherited structs are valid ? Barry Schwarz <schwarzb@dqel.com> - 2013-01-01 17:59 -0800
    Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-02 10:18 -0800
  Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-01 21:06 -0500
    Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-02 10:45 -0800
      Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-02 19:56 -0500
        Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-03 08:28 -0500
        Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-03 15:31 -0800
          Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-03 20:55 -0500
            Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-03 21:00 -0500
              Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-04 12:56 -0500
            Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-04 12:59 -0500
            Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-06 20:00 -0800
              Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-07 00:47 -0500
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-06 23:06 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-07 04:03 -0500
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-07 08:25 -0500
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-13 10:34 -0800
                Re: Off-Topic: Irritating Posting Patterns Shao Miller <sha0.miller@gmail.com> - 2013-01-13 16:00 -0500
                Re: Off-Topic: Irritating Posting Patterns Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-14 12:27 -0800
              Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-07 07:41 -0500
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-12 14:52 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-13 15:19 -0500
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-14 12:04 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-14 18:52 -0500
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-16 00:01 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-16 05:43 -0500
                Re: [union] Pointers to inherited structs are valid ? Geoff <geoff@invalid.invalid> - 2013-01-16 09:01 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-16 18:32 -0500
                Re: [union] Pointers to inherited structs are valid ? Geoff <geoff@invalid.invalid> - 2013-01-16 17:32 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-16 20:57 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-17 07:55 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-17 16:47 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-18 08:41 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-18 15:53 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-18 17:38 -0800
                Re: [union] Pointers to inherited structs are valid ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-19 02:31 +0000
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-18 23:15 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-19 20:03 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-20 02:19 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-20 07:57 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-20 15:25 -0500
                Re: [union] Pointers to inherited structs are valid ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-20 23:58 +0000
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-20 21:30 -0500
                Re: [union] Pointers to inherited structs are valid ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-21 02:53 +0000
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-21 00:05 -0500
                Re: [union] Pointers to inherited structs are valid ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-21 16:31 +0000
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-21 14:07 -0500
                Re: [union] Pointers to inherited structs are valid ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-21 21:05 +0000
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-21 17:13 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-21 16:11 -0800
                Re: [union] Pointers to inherited structs are valid ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-22 04:59 +0000
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-22 01:05 -0500
                Re: [union] Pointers to inherited structs are valid ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-22 14:53 +0000
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-22 08:38 -0800
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-21 20:53 -0800
                Re: [union] Pointers to inherited structs are valid ? Philip Lantz <prl@canterey.us> - 2013-01-22 00:58 -0800
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-22 08:40 -0800
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-22 23:32 -0800
                Re: [union] Pointers to inherited structs are valid ? Philip Lantz <prl@canterey.us> - 2013-01-23 23:21 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-24 04:53 -0500
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-25 10:49 -0800
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-22 08:25 -0800
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-22 23:41 -0800
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-21 13:32 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-21 17:46 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-22 07:43 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-22 16:07 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-22 14:15 -0800
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-22 14:31 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-22 21:32 -0500
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-23 17:17 -0500
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-23 19:49 -0500
                Re: [union] Pointers to inherited structs are valid ? Geoff <geoff@invalid.invalid> - 2013-01-23 18:55 -0800
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-24 11:01 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-24 14:11 -0500
                Re: [union] Pointers to inherited structs are valid ? Geoff <geoff@invalid.invalid> - 2013-01-22 17:51 -0800
                Re: [union] Pointers to inherited structs are valid ? Philip Lantz <prl@canterey.us> - 2013-01-20 16:48 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-20 21:33 -0500
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-21 09:23 -0800
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-20 17:07 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-20 22:20 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-20 22:02 -0800
                Re: [union] Pointers to inherited structs are valid ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-21 07:00 +0000
                Re: [union] Pointers to inherited structs are valid ? James Kuyper <jameskuyper@verizon.net> - 2013-01-21 08:17 -0500
                Re: [union] Pointers to inherited structs are valid ? Dr Nick <nospam-4@temporary-address.org.uk> - 2013-01-21 14:13 +0000
                Re: [union] Pointers to inherited structs are valid ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-21 14:12 +0000
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-21 08:20 -0800
                Re: [union] Pointers to inherited structs are valid ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-21 20:41 +0000
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-21 12:37 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-21 12:17 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-21 16:33 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-21 15:50 -0800
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-21 19:45 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-22 00:18 -0500
                Re: [union] Pointers to inherited structs are valid ? Keith Thompson <kst-u@mib.org> - 2013-01-22 08:01 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-18 23:02 -0500
                Re: [union] Pointers to inherited structs are valid ? Philip Lantz <prl@canterey.us> - 2013-01-19 01:28 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-19 12:08 -0500
                Re: [union] Pointers to inherited structs are valid ? Geoff <geoff@invalid.invalid> - 2013-01-21 09:27 -0800
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-21 12:46 -0500
                Re: [union] Pointers to inherited structs are valid ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-21 20:48 +0000
                Re: [union] Pointers to inherited structs are valid ? Geoff <geoff@invalid.invalid> - 2013-01-21 18:52 -0800
                Re: [union] Pointers to inherited structs are valid ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-22 04:07 +0000
                Re: [union] Pointers to inherited structs are valid ? Shao Miller <sha0.miller@gmail.com> - 2013-01-21 23:15 -0500
                Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-16 10:59 -0800
  Re: [union] Pointers to inherited structs are valid ? Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-02 10:34 -0800

csiph-web