Another "D" idea (Oh no, not again!)

Roland McGrath rk9005 at cca.ucsf.edu
Sun Mar 6 06:03:35 AEST 1988


I have yet another idea for "D".  This one is quite a bit tamer than some
of the others I've seen.

How about anonymous structs and unions?
For example:
	struct { toggle:1; };
	union { int i; float f; }
	x() { return(toggle ? i : f); }
Granted, the main use of global anonymous structs is for less-than-a-char
values and anonymous unions look alot like Fortran equivalences (God forbid
that C (or D) should get *anything* for (ugh!) Fortran!!! ;-).
But I think these could be useful.  Anyway, the most useful use of them
would be inside structs and unions.  The only problem is with the syntax,
because
	struct x { int a, b; }
	struct x;
does nothing but define the type.  I suppose we could introduce
an "anonymous" keyword or something, but that seems ugly.
However, assuming we did that, something like
	struct popen_info {
		FILE;
		int pid, status;
	};
could be interesting.  Then popen could return a (FILE *)(struct popen_info),
including whatever was needed for file i/o in the FILE part and the pid
of the child in the rest; and when pclose got this thing, it could pass
a (FILE *) (struct popen_info) to fclose and fclose would never know the
difference.

Now this may be a bad example (I can find some serious problems with it
myself), but I think it might be a good idea.  The main problem is the
syntax of anonymous tagged structs.


On the switch/fallthrough discussion, I think the best solution is
to have two statements, switch and select (or something), each with
different default behavior.  gotos to case labels are also a good idea.
(And "goto default".)  A Cish language developed around here has these
things (although I think it's got "select" being the semantics of the
present "switch" statement, which I think is wrong); it's also got
things like "break 2;" (e.g.,
	while (x > 0) { while (y != -1) { if (a) break 2; } }
), which gets into the named control-loop thing, so these are not just
the products of my demented mind.  They are the products of the demented
minds of people who get paid lots of money to think of them.
-- 
	Roland McGrath
ARPA: roland at rtsg.lbl.gov roland at lbl-rtsg.arpa
UUCP: ...!ucbvax!lbl-rtsg.arpa!roland



More information about the Comp.lang.c mailing list