Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sol.ctr.columbia.edu!cica!iuvax!mayer From: mayer@iuvax.cs.indiana.edu (Mayer Goldberg) Newsgroups: comp.lang.c Subject: Request for Comments: Aggregate Assignment in C ... Message-ID: <77546@iuvax.cs.indiana.edu> Date: 11 Dec 90 03:42:11 GMT Organization: Indiana University, Bloomington Lines: 47 Pascal programmers who learn C, frequently complain of C's lack of a "with" construct. We propose an alternative to adding such a keyword, through a natural extention of C's aggregate initialization statement. Consider the following program fragment: struct ag { int a, b, c; }; struct ag my_vec = {1, 2, 3}; This form of an "assignment" is permitted only during the initialization of a variable (at compile time). Any other way of assignment to fields in my_vec will have to be done by routing through my_vec, as in: my_vec.a = 4; my_vec.c = 7; /* etc. */ 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 for example we wished to assign 2 and 3 to the 'a' and 'b' fields of my_vec, any one of the following should be ok: my_vec = {2, 3}; or my_vec = {2, 3,}; This mechanism should work for both structures and arrays. This solves the "with" problem in C. It also opens a delicious can of worms: Should the order of evaluation of the aggregated expressions be specified? Perhaps not, for this would be in line with C's philosophy of not specifying the order of evaluation of parameters to a function, or alternately, we could demand a left-to-right order of evaluation as implied by the comma operator. Mayer Goldberg Nick Cline mayer@iuvax.cs.indiana.edu cline@silver.ucs.indiana.edu