3 ms·
I thought you were not able to initialize bitfield members like that in struct. Am I misremembering, was that something else or is it compiler/c++ release depe
by shultays 4y ago
I thought you were not able to initialize bitfield members like that in struct. Am I misremembering, was that something else or is it compiler/c++ release dependent?
- eqvinox 4y agoYou can absolutely initialize bitfield members in structs, not sure where your memory is from… maybe it was broken on some specific compiler vendors/versions?
- scaredginger 4y agoPossible they were just pre-C++11
- MontyCarloHall 4y agoThis has been possible since C89. See 3.5.2.1 of the C89 rationale [0]. It is architecture/compiler dependent though. This is explicitly acknowledged in the rationale document: “Since some existing implementations, in the interest of enhanced access time, leave internal holes larger than absolutely necessary, it is not clear that a portable deterministic method can be given for traversing a structure field by field.” [0] https://www.lysator.liu.se/c/rat/c5.html https://www.lysator.liu.se/c/rat/c5.html
- scaredginger 4y agoI think they were referring to the default member initializer, a feature added in C++11 not exclusive to bitfields. I couldn't see any reference to anything similar in what you linked (admittedly, I skimmed though). For example: struct X { int defaulted = 1; // 1 is the default member initializer };
- MontyCarloHall 4y ago>I think they were referring to the default member initializer Ah, that would make more sense. The combination of bitfield and default initializer syntax does look especially odd, since both features are rarely used IME. >I couldn't see any reference to anything similar in what you linked Indeed, there is no way to specify default values for a C struct at definition time.
- shultays 4y ago<source>(6): error C7582: 't': default member initializers for bit-fields requires at least '/std:c++20' It is c++20 apparently https://godbolt.org/z/qvso544dr https://godbolt.org/z/qvso544dr
- eqvinox 4y agoAh, I misunderstood / didn't look properly and failed to notice this is a default value in the struct definition. My bad.
- cesaref 4y agoThis is a c++20 feature
- shultays 4y agoAh right, I tried again <source>(6): error C7582: 't': default member initializers for bit-fields requires at least '/std:c++20' Nice to see they also improved such "legacy" stuff