Shared initial struct elements... history provides an answer?

Kevin Martin kpmartin at watmath.UUCP
Fri Jan 18 12:11:21 AEST 1985


In article <6284 at boring.UUCP> guido at mcvax.UUCP (Guido van Rossum) writes:
>(Re: allowing 'partially qualified references' when a structure element
>is unnamed and is itself a structure.)
>
>This proposal doesn't solve any problem.
Actually, it does solve a problem. It is just that there is some confusion
as to what problem is to be solved. I suspect I am the person who has
deviated from the original problem, into one of my own pet peeves.

My proposal makes it easier to use complex nestings of structures within
unions within structures within..., which improves *one* of the solutions
for the several-types-of-structures-with-common-elements problem, namely
the solution "declare one structure containing the shared elements, and a
union of all the different variations". The only *other* problem with this
solution is that the combined structure is at least as big as the largest
of its variants. The user can only 'trim' the structure if the compiler
actually generates the fields in the declared order (note that this is
a necessary but not sufficient condition).

>The idea of parially qualified references in itself is nice, though, and
>if introduced generally (using the Cobol or PL/1 rules, for instance),
>might also be used for shared portions of larger structures as in the
>original proposal.
I was only thinking of allowing the 'partially qualified references' in cases
where the declarator was actually omitted from the original element
declaration, e.g., in:
    struct {
        union {
            int x;
            char *y;
            float z;
        } onion;
        char foo;
    } var;
var.onion.x is legal, but var.x isn't, and in
    struct {
        union {
            int x;
            char *y;
            float z;
        };
        char foo;
    } var;
var.x is legal, but var.onion.x (obviously!) isn't.

            Kevin Martin, UofW Software Development Group



More information about the Comp.lang.c mailing list