Topic: Anonymous Union


Author: hsganesh <hsganesh@hnssysb.hns.com>
Date: 1995/08/17
Raw View
Hi friends,

 It is regarding anonymous union. Anonymous union defines an object
 rather than a type. It appears very interesting to me why such a
 feature is in the language.

 ( I am a new user of comp.std.c++. I don't know whether simillar
   debate was there earlier in this news group. )

  I guess it must be having some concrete applications which
 calls for such a feature.

 One application I can think of is to define mutually independent
 set of temporary variables ( used in storing intermediate results,
 loop indices  etc. ) In code fragments below I think the last one
 based on anonymous union is superior compared to first three.

 1. int loop_index; // Some variable names,mutually independent
  int save_x;
  // etc ..

  // use loop_index,save_x,etc.. in implementation.

 2. int temp; // temp will be used where loop_index,save_x etc. is
     // required in an implementation.

 3. union {
    int loop_index;
    int save_x;
    // etc ..
  } temp;

  // temp.loop_index and temp.save_x,etc.. is used in implementation.

 4. union { // Anonymous ! and defines an object.
    int loop_index;
    int save_x;
    // etc ..
  }

  // use loop_index,save_x with same syntax as 1.

 Any better applications for anonymous unions you can think off ?
 Why anounymous structure is a 'warning' ? Or in other words
  does it not have any application ? or allowing such feature in the
 language leads to any conflict ?


     Thank you,
     Ganesh HS. (hsganesh@hss.hns.com).
     Hughes Software Systems,
     International Trade Tower,
     2nd Floor,
     Nehru Place,
     New Delhi - INDIA.



[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]