0

I'm looking at this file. The code looks like the following

bool isVRegCycle : 1;

The only time I've seen something like this before is in C in structs when bitfields are used. How do I interpret this in C++?

Any help is appreciated.

flashburn
  • 4,180
  • 7
  • 54
  • 109
  • The same as in C, it is a bitfield interpreted as `bool`. – syntagma Sep 22 '15 at 21:36
  • It's a bitfield. C++ is superset of C (almost), so I'm not sure why you'd think this was any different. – rlbond Sep 22 '15 at 21:42
  • @rlbond I thought it was different because it is used with bool. I only saw it used in C with integers. – flashburn Sep 22 '15 at 21:46
  • Possible duplicate: http://stackoverflow.com/questions/1604968/what-does-a-colon-in-a-struct-declaration-mean-such-as-1-7-16-or-32 – Tas Sep 22 '15 at 22:31

1 Answers1

1

It's the same in C++, a bit-field.

C++ has nearly all of C as a subset.

The difference are however enough that it's best to treat them as two different languages.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • Let's talk packing. Does each bool myVar : 1 occupy a single byte or 8 of those occupy a byte? – flashburn Sep 22 '15 at 21:38
  • 1
    @flashburn: 8 of those in sequence, on an 8-bit byte machine, should ideally occupy one byte. But I think it depends on the compiler and options, i.e. not guaranteed (just allowed) by the standard. – Cheers and hth. - Alf Sep 22 '15 at 21:40