Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.compilers > #2760

Re: Union C++ standard

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.compilers
Subject Re: Union C++ standard
Date 2021-11-29 21:00 +0100
Organization A noiseless patient Spider
Message-ID <21-11-013@comp.compilers> (permalink)
References <21-11-004@comp.compilers> <21-11-008@comp.compilers> <21-11-009@comp.compilers> <21-11-010@comp.compilers> <21-11-011@comp.compilers>

Show all headers | View raw


On 29/11/2021 01:09, Derek Jones wrote:
> David,
>
>>>> In C, type-punning via unions is allowed (i.e., fully defined behaviour
>>>
>>> That is not true.  Writing into one member and then reading from
>>> another member is undefined behavior.
>>
>> No, it is correct.  It would be helpful if you looked at the full
>
> You have misunderstood the C conformance model, which revolves around
> the use of "shall" and "shall not", and the kind of section in which
> they appear (e.g., Constraints).  See:
> http://c0x.shape-of-code.com/4..html
>
> For a longer discussion see: http://knosof.co.uk/cbook/

I was not aware of your qualifications when I posted earlier - you have
been directly involved in things that I can only infer from reading the
standards and other material.

Let me put it this way.  Those of us who read the C standards, but were
not involved in writing them, do our best to interpret the precise
meaning of the words in the normative text.  Those meanings are not
always clear.  When we see examples or footnotes, we know they were
added by the same people that wrote the standard, and are used as
clarification for the meaning of the normative text.  The footnote
(added, as you say, in a C99 TC in response to a defect report - and
therefore AIUI as much part of C99 standard as the original published
text since the TC's replace previous versions) makes it perfectly clear
that type-punning via unions is defined behaviour in C.  This codifies
the existing practice supported by most (if not all) C compilers, and
relied upon by code.

Since the change was a clarifying footnote, not a change to the
normative text, the implication is that the normative text was always
intended to support these semantics.  The only three alternatives I see
to that is that the footnote was added by some committee members who
disagreed with what other committee members wrote in the normative text,
that the committee changed their minds about union semantics but did not
change the normative text, or that the footnote was deliberately added
to confuse people.  None of these alternatives is appealing.

If my reasoning here is faulty, I'd be grateful if you could point out
the flaw.

David

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Union C++ standard Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2021-11-25 11:11 +0100
  Re: Union C++ standard Kaz Kylheku <480-992-1380@kylheku.com> - 2021-11-26 18:06 +0000
  Re: Union C++ standard gah4 <gah4@u.washington.edu> - 2021-11-26 12:16 -0800
  Re: Union C++ standard David Brown <david.brown@hesbynett.no> - 2021-11-27 16:59 +0100
    Re: Union C++ standard Derek Jones <derek@NOSPAM-knosof.co.uk> - 2021-11-28 12:51 +0000
      Re: Union C++ standard David Brown <david.brown@hesbynett.no> - 2021-11-28 19:00 +0100
        Re: Union C++ standard Derek Jones <derek@NOSPAM-knosof.co.uk> - 2021-11-29 00:09 +0000
          Re: Union C++ standard David Brown <david.brown@hesbynett.no> - 2021-11-29 21:00 +0100
            Re: Union C++ standard Derek Jones <derek@NOSPAM-knosof.co.uk> - 2021-11-30 00:46 +0000
              Re: Union C++ standard George Neuner <gneuner2@comcast.net> - 2021-11-30 17:18 -0500
                Re: Union C++ standard terminology Derek Jones <derek@knosof.co.uk> - 2021-12-01 13:35 +0000
              Re: Union C++ standard David Brown <david.brown@hesbynett.no> - 2021-11-30 23:24 +0100
        Re: Union C++ standard Kaz Kylheku <480-992-1380@kylheku.com> - 2021-11-29 16:39 +0000
          Re: Union C++ standard Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-11-29 14:32 -0800

csiph-web