Request for Comments: Aggregate Assignment in C ...
Richard A. O'Keefe
ok at goanna.cs.rmit.oz.au
Tue Dec 11 17:43:46 AEST 1990
In article <77546 at iuvax.cs.indiana.edu>, mayer at iuvax.cs.indiana.edu (Mayer Goldberg) writes:
> We submit that a better way of doing this would be to allow a
> kind of assignment that we allow during initialization.
> Something like:
> my_vec = {4,, 7};
If you want Ada, you know where to find it.
It you want to make it easy for people to introduce subtle and
difficult-to-locate mistakes in their programs, keep it up.
A better approach is to write a function that fills in records
struct ag mk_ag(int a, int b, int c)
{ struct ag ans; ans.a = a, ans.b = b, ans.c = c; return ans; }
Then the struct declaration can have new fields added, or the fields
re-ordered, and
my_vec = mk_ag(4, 0, 7);
will still work. (Hint: this is why Ada record constructors let you
use keywords.)
If your compiler supports inlining (gcc, for example) struct-building
functions are good candidates for inlining.
--
The Marxists have merely _interpreted_ Marxism in various ways;
the point, however, is to _change_ it. -- R. Hochhuth.
More information about the Comp.lang.c
mailing list