Article View: comp.std.c++
Article #1732Anonymous Union
From: hsganesh
Date: Thu, 17 Aug 1995 15:41
Date: Thu, 17 Aug 1995 15:41
61 lines
2532 bytes
2532 bytes
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. ]
Technical Details
Message-ID:
<40vdnn$ee@hnssysb.hns.com>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: hsganesh <hsganesh@hnssysb.hns.com> Newsgroups: comp.std.c++ Subject: Anonymous Union Date: 17 Aug 1995 15:41:16 GMT Organization: Hughes Network Systems Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <40vdnn$ee@hnssysb.hns.com> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; conversions="7bit" Content-Transfer-Encoding: 7bit X-Nntp-Posting-Host: vikram.hss.hns.com X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.03 9000/735) X-Url: file:/home/hsganesh/etc/union.msg X-Lines: 57 Content-Length: 1616 Originator: clamage@taumet