[PATCH v4] ungetc: Guarantee single char pushback

Siddhesh Poyarekar siddhesh@sourceware.org
Thu Dec 12 14:20:29 GMT 2024


On 2024-12-12 08:00, Maciej W. Rozycki wrote:
> On Thu, 12 Dec 2024, Siddhesh Poyarekar wrote:
> 
>>>> gcc and clang both appear to pack in the struct just fine, which
>>>> effectively
>>>> gives flags2 3-bytes storage and _short_backupbuf right next to it.  Maybe
>>>> I've misunderstood the issue you're trying to point out, could you please
>>>> elaborate?
>>>
>>>    Indeed a bit-field does get packed with an eligible adjacent non-bitfield
>>> member of the structure, although ISO C defers storage unit allocation to
>>> the implementation and therefore I do believe it is down to the individual
>>> platform-specific ABI.
>>>
>>>    Then e.g. the o32 MIPS ABI has this clause[1]:
>>>
>>> "* Bit-fields can share a storage unit with other struct/union members,
>>>      including members that are not bit-fields.  Of course, struct members
>>>      occupy different parts of the storage unit."
>>
>> That sounds like it's saying that distinct members cannot share the smallest
>> addressable unit, i.e. a byte, which is fine.
> 
>   Obviously struct members cannot overlap, but more importantly it does say
> non-bitfield members can share a storage unit with bit-fields, e.g. one
> used for the "int" type, just as bit-field members do between themselves.

Right, which is why I reckon the layout I'm proposing is OK; would you 
agree?

Thanks,
Sid


More information about the Libc-alpha mailing list