null union name allowed?

Daemon dae at psuvax1.UUCP
Sat Jan 5 13:30:11 AEST 1985


Consider the following fragment:
struct foo
	{
	int bar;
	union
		{
		char grill;
		long diner;
		};
	} fubar;
fubar.grill = 'e';

(1) is the null union name allowed ( K&R, ANSI ) ?
(2) do compilers In The Real World allow it ( Mark Williams,
DeSmet, Lattice, etc) ?

4.2 cc allows the structure definition, but bombs on the
fubar.grill.... line--mumbles something about illegal member usage.

I personally would like to see this added (if it's an addition) for the
following reasons:

(1) It seems that it's already (in some places) almost there,
(2) You get the space-saving you want without adding a useless
	intermediate member.

Side issue:
4.2bsd has a

union wait
	{
	stuff;
	stuff;
	};
Is this formally allowed?  Is it allowed in practice?
Personally, I feel this is a bit bogus, but it seems
to be a try at getting around a

struct wait
	{
	union foo
		{
		stuff;
		stuff;
		};
	};
Perhaps unnamed unions are the solution?  By the way, I seem
to remember some c compiler that had a (one) struct 0, and if
you said "struct x;" you got whatever struct 0 was...does this
ring a bell with anybody?

Replies to ...gondor!dae; The usual mumbles about mail and posting
summaries apply.
-- 

 
 \ / \/
  \  / From the furnace of Daemon ( ...{psuvax1,gondor,shire}!dae )
   \/  (814) 237-1901 "I will have no covenants but proximities" [Emerson]

When the going gets tough, the weird turn pro.



More information about the Comp.lang.c mailing list