Request for Comments: Aggregate Assignment in C ...

Jan Brittenson bson at rice-chex.ai.mit.edu
Thu Dec 13 16:02:20 AEST 1990


In article <77546 at iuvax.cs.indiana.edu>
   mayer at iuvax.cs.indiana.edu (Mayer Goldberg) writes:

 >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).

   Perhaps you should take a look at GNU C. Its aggregate initializer
doesn't allow you to "skip" members, but I fid it much more useful
than Pascal's WITH clause.


/* Feed me to GCC! */
#include <stdio.h>

struct barf {
  int x, y;
};

void print_barf(barfstuff)
  struct barf barfstuff;
{
  printf("barf: x=%d, y=%d\n", barfstuff.x, barfstuff.y);
}

main()
{
  print_barf( (struct barf) {2, 3} );
}



More information about the Comp.lang.c mailing list