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


Groups > comp.lang.c++ > #7262 > unrolled thread

size of bit field

Started byNikolay Moskvichev <nikolay.moskvichev@gmail.com>
First post2011-06-29 21:37 -0700
Last post2011-06-30 17:38 +1200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.c++


Contents

  size of bit field Nikolay Moskvichev <nikolay.moskvichev@gmail.com> - 2011-06-29 21:37 -0700
    Re: size of bit field Ian Collins <ian-news@hotmail.com> - 2011-06-30 17:38 +1200

#7262 — size of bit field

FromNikolay Moskvichev <nikolay.moskvichev@gmail.com>
Date2011-06-29 21:37 -0700
Subjectsize of bit field
Message-ID<e99d1a5c-66e2-4bb8-a4b7-6a002f4c6f8a@g16g2000yqg.googlegroups.com>
Hello All.

size of this bit_field is 2 for gcc or borland, and 4 for msvc 2008
and 2010.
Can you please explain me this behaviour?


#include <iostream>
#pragma pack(push,1)

struct  bit_field {
  unsigned  f1  : 5;
  unsigned  f2  : 4;
  unsigned  f3  : 7;
};

#pragma pack(pop)

int main()
{
   std::cout<<sizeof(bit_field)<<std::endl;
}

Thanks.

[toc] | [next] | [standalone]


#7263

FromIan Collins <ian-news@hotmail.com>
Date2011-06-30 17:38 +1200
Message-ID<972geqFfpqU10@mid.individual.net>
In reply to#7262
On 06/30/11 04:37 PM, Nikolay Moskvichev wrote:
> Hello All.
>
> size of this bit_field is 2 for gcc or borland, and 4 for msvc 2008
> and 2010.
> Can you please explain me this behaviour?
>
>
> #include<iostream>
> #pragma pack(push,1)

This is compiler specific, so you would be better off asking on a more 
specialised group.

My *guess* is that the directive is ignored by msvc.

-- 
Ian Collins

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web