Clarify reasoning for STYLE #29 #170
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
in what way is this poorly specified? i'm not an expert in this area, but i've used bitfields within unions before and didn't find any ambiguity apart from the standards deferring to the target platform's abi for bitfield ordering. if this is the concern, either mention it or include a relevant source.
It is because of ordering.
Long winded explanation:
From the C89 draft: 3.5.2.1 Structure and union specifiers
The standards do not defer except to the compiler writer, who is (knowing the type of person that works on compilers) probably a chainsaw-wielding lunatic.
There are some portable uses of bitfields, e.g.
or even
to have two possible layouts for keeping track of strings or whatever. But this:
while probably working on x64, only works if
double
is 64band while the first two are sloppy assumptions (especially the latter, which seems obvious to me, perhaps because I have used multiple C compilers), the third one is a subtler thing. That means this code
could return
0
or1
, unpredictably.So bitfields within unions can theoretically be used just fine, it's just that their typical use (chopping a variable into fields) results in very subtly buggy code, and their correct use is not very practical.
got it, thanks for clarifying. any thoughts on moving it to the "Avoid" section and adding a reference to cppreference's bit-field page?
cc @emma
(sorry for the premature comment+close misclick)
I'm fine with "avoid" rather than a strict ban, though I would prefer we either cite a standard/draft directly.
i agree that citing an actual standard would be preferable. i only mentioned cppreference because the actual targeted standard by bonsai has never been entirely clear to me and it saves us the effort of tracking down the right spot again if the target ever does change.
Just give me the standards hyperlink and I will make it happen.
I wondered if targeted standard matters, but the newest draft has roughly the same language:
(C standard draft N3220, section 6.7.3.2, paragraph 13)
I don't remember what C standard we target. I've made a note to get back to this and decide on a hyperlink to use.