Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #6177

unions

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!transit3.readnews.com!news-out.readnews.com!news-xxxfer.readnews.com!panix!not-for-mail
From Ruben Safir <ruben@mrbrklyn.com>
Newsgroups comp.lang.c++
Subject unions
Date Sat, 4 Jun 2011 05:26:57 +0000 (UTC)
Organization PANIX Public Access Internet and UNIX, NYC
Lines 27
Message-ID <iscfn1$keo$8@reader1.panix.com> (permalink)
NNTP-Posting-Host www2.mrbrklyn.com
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Trace reader1.panix.com 1307165217 20952 96.57.23.82 (4 Jun 2011 05:26:57 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Sat, 4 Jun 2011 05:26:57 +0000 (UTC)
X-Blackjet Blackjet is a Yankee Fan
X-DRMisTHEFT Use GNU Linux today
X-From A Dark Cloud
X-LOCATION Brooklyn NY - Forget abou' it!
X-NYLXS Really - yah think computers are supposed to be broken?
User-Agent Pan/0.133 (House of Butterflies)
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:6177

Show key headers only | View raw


There are some things, that as I learned to program, I learned them, 
decided they suck and would never use them, and then put them away.  
unions are one of these things (static was another and complex #define 
yet another).

But I took this employment exam this week and 10% of the questions 
involved unions.  As I understood unions, union sub-objects just step on 
each other in binary in the allocated space where they exist (talk about 
a snake pit for potential bugs).  Am I missing something about them?  I 
started to have deep doubts about what I thought I knew.


union {
	double x;
	char a[10];
} myunion;

myunion.a[0] = 'A';
myunion.a[1] = 'A';
myunion.a[2] = 'A';
myunion.a[3] = 'A';

std::cout << myunion.x << std::end 
is going to spit out some binary translation of a double with 4 bytes of 
65 dec, whatever that is.

Ruben

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

unions Ruben Safir <ruben@mrbrklyn.com> - 2011-06-04 05:26 +0000
  Re: unions Ian Collins <ian-news@hotmail.com> - 2011-06-04 17:38 +1200
    Re: unions Ruben Safir <ruben@mrbrklyn.com> - 2011-06-04 05:45 +0000
      Re: unions Ian Collins <ian-news@hotmail.com> - 2011-06-04 18:04 +1200
        Re: unions Ruben Safir <ruben@mrbrklyn.com> - 2011-06-04 06:13 +0000
  Re: unions Öö Tiib <ootiib@hot.ee> - 2011-06-04 04:54 -0700
  Re: unions Edek <edek.pienkowski@gmail.com> - 2011-06-04 19:59 +0200
    Re: unions Vaclav Haisman <v.haisman@sh.cvut.cz> - 2011-06-04 20:13 +0200
      Re: unions Edek <edek.pienkowski@gmail.com> - 2011-06-04 22:34 +0200
        Re: unions Vaclav Haisman <v.haisman@sh.cvut.cz> - 2011-06-05 07:29 +0200
  Re: unions Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-06-09 09:19 +0000
  Re: unions Keith <kbelder@gmail.com> - 2011-06-09 11:17 -0700
    Re: unions Victor Bazarov <v.bazarov@comcast.invalid> - 2011-06-09 14:29 -0400
    Re: unions Edek <edek.pienkowski@gmail.com> - 2011-06-10 13:16 +0200

csiph-web