Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!linus!philabs!cmcl2!seismo!brl-tgr!tgr!rbbb@rice.ARPA From: rbbb@rice.ARPA (David Chase) Newsgroups: net.lang.c Subject: Unions and structures Message-ID: <8333@brl-tgr.ARPA> Date: Wed, 20-Feb-85 10:04:02 EST Article-I.D.: brl-tgr.8333 Posted: Wed Feb 20 10:04:02 1985 Date-Received: Sun, 24-Feb-85 04:16:10 EST Sender: news@brl-tgr.ARPA Organization: Ballistic Research Lab Lines: 51 Someone has probably been over this before, but just in case, will someone PLEASE grab the ear of someone on the ANSI committee and ask them to make structures and unions first-class sort of datatypes. Examples of problems I have had using the Berkeley C compiler are: 1) "structure reference must be addressable" ================================================================ union foo { float f; int i; }; union foo bar(); barf() { return bar().i; /* This line gives the error */ } ================================================================ 2) "no automatic aggregate initialization" ================================================================ struct foo { float f; int i; }; struct foo bar(); barf() { struct foo bozo = bar(); /* This line gives the error */ } ================================================================ I find these restrictions fairly stupid and arbitrary, given that the workarounds are so utterly trivial. For the union, assigning into a temporary and then returning the union element of the temporary works; for the structure, just doing the declaration and the assignment in separate statements passes. I'm also a little hacked that the compiler blows off register declarations for unions even when all members are the same size and fit in a register (This of course is an implementation nit, not a language specification, but programmers will be less likely to use unions if they "know" the union will not be stored in a register.). I wrote a piece of code using unions hoping that it would be more portable than if I just went casting a hunk of storage every-which-way, but now I find my code is LESS portable because of antique compilers that won't let me assign unions. C needs a standard, even a bad one, just so I can quit second-guessing what sort of brain damage I'm likely to encounter on the next machine I use. I'd also like to learn one language, not 3 or 4 that look enough alike to confuse me. Venting my frustrations on people who might be able to prevent them in the future, David Chase