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


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

Re: Is a union a kind of class?

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.std.c++
Subject Re: Is a union a kind of class?
Date 2013-12-27 13:11 -0600
Organization Self
Message-ID <52B84DE2.2070604@verizon.net> (permalink)
References <52204496.5050408@bawi.org> <24874a99-32a8-475d-88c2-36631dfb45ba@googlegroups.com> <c8rtu.34611$O25.31034@fx21.iad>

Show all headers | View raw


On 12/22/2013 08:27 PM, news wrote:
>
> 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 necessarily. The minimum possible size will be sizeof(double) +
alignof(double), which could be smaller than 2*sizeof(double) - in
principle, it could be as small as sizeof(double)  + 1. The actual size
could be larger than the minimum - some implementations give all classes
the same alignment requirement, which would be alignof(max_align_t), and
could in principle be larger than 2*sizeof(double), though it's rather
unlikely.


-- 
[ 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