Leading padding in unions

C

CBFalconer

Keith said:
.... snip ...


Backus-Naur is a formal specification of the grammar, not of
the semantics.

Well, maybe I am showing my ignorance, but to me 'semantics' is
such things as:

"Once an identifier name has been attached to an object, that
identifier name is not available while that object is available."

or roughly equivalent verbiage. I see no formal way to specify
semantics.
 
C

CBFalconer

Richard said:
I have a book which contains a description of Pascal which is
considerably more formal than the C Standard. I was under the
impression that it was used in the preparation (or derived from
a document which was) of the Pascal Standard. I may have been
mistaken.

Just as C grew up around the description in K&RI, Pascal grew up
around Jensen & Wirths "Pascal User manual and Report". Both were
eventually followed by ISO standards. For Pascal, see ISO-7185 and
ISO-10206.
 
K

Keith Thompson

CBFalconer said:
Well, maybe I am showing my ignorance, but to me 'semantics' is
such things as:

"Once an identifier name has been attached to an object, that
identifier name is not available while that object is available."

or roughly equivalent verbiage. I see no formal way to specify
semantics.

Google "formal semantics". Formally specifying semantics for a large
programming language (C counts as large in this context) is difficult,
but it can be done.
 
D

Dik T. Winter

> Well, maybe I am showing my ignorance, but to me 'semantics' is
> such things as:
>
> "Once an identifier name has been attached to an object, that
> identifier name is not available while that object is available."
>
> or roughly equivalent verbiage. I see no formal way to specify
> semantics.

Have a look at the grammar of Algol 68. In that language the *grammar*
specifies that an identifier may not have two meanings at once (and
quite a lot more).
 
S

sp12341234

Whether unions can have leading padding is the least of your worries.
Try to write a strictly conforming program by referring to only the
wording of the Standard.

    int main(void)
    {
         return 0;
    }

Is that strictly conforming? The answer (*possible* answer) may
surprise you.

It appears to be conforming.
I assume you've considered all the relevant clause 6 subclauses and
don't find any of them convincing enough, so I'll try something
fresh with clause 7.

There's the fact that offsetof() is explicitly restricted to structures.
This has the implicit statement that offsetof() is useless for unions,
presumably because unions can't have leading padding.

Whether such indirect arguments appeal to you, I'll let you decide.

Good point. But I was looking for something a little more reliable,
instead of just "made sense".

--
 
A

Antoninus Twink

I see no formal way to specify semantics.

Then why in the hell don't you spend a quarter of an hour with Google to
familiarize yourself with the subject, instead of confidently
pontificating about something that you haven't got the first clue about?
Jeez.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top