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


Groups > comp.std.c++ > #699

Re: Is a union a kind of class?

Message-ID <c8rtu.34611$O25.31034@fx21.iad> (permalink)
Newsgroups comp.std.c++
From "news" <news@fx21.iad.highwinds-media.com>
Subject Re: Is a union a kind of class?
Organization unknown
References <52204496.5050408@bawi.org> <24874a99-32a8-475d-88c2-36631dfb45ba@googlegroups.com>
Date 2013-12-22 19:27 -0600

Show all headers | View raw


On 12/19/13 13:24, johnolithicsoftware@googlemail.com wrote:
[snip]

> The size of a union is equal to the size of it's largest data member
> if I'm not mistaken.

What about:

  union dbl_charray
  {
      double dbl;
      char [sizeof(double)+1] charray;
  };

IIUC, in order to satisfy the alignment requirements of the double,
the size would have to be 2*sizeof(double), not just sizeof(double)+1.

Not tested with actual compile and test of size.

-Larry


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Is a union a kind of class? Seungbeom Kim <musiphil@bawi.org> - 2013-08-31 01:12 -0600
  Re: Is a union a kind of class? Daniel Krügler <daniel.kruegler@googlemail.com> - 2013-08-31 23:52 -0700
  Re: Is a union a kind of class? James Kuyper <jameskuyper@verizon.net> - 2013-08-31 23:52 -0700
  Re: Is a union a kind of class? johnolithicsoftware@googlemail.com - 2013-12-19 11:24 -0800
    Re: Is a union a kind of class? "news" <news@fx21.iad.highwinds-media.com> - 2013-12-22 19:27 -0600
      Re: Is a union a kind of class? James Kuyper <jameskuyper@verizon.net> - 2013-12-27 13:11 -0600
        Re: Is a union a kind of class? evansl <cppljevans@googlemail.com> - 2013-12-29 23:00 -0600
          Re: Is a union a kind of class? James Kuyper <jameskuyper@verizon.net> - 2013-12-31 17:45 -0600

csiph-web