[cfe-dev] different signedness for bitfield 'char' and plain 'char'

Richard Smith richard at metafoo.co.uk
Tue Jul 30 11:19:48 PDT 2013


On Tue, Jul 30, 2013 at 10:51 AM, Robert Lytton <robert at xmos.com> wrote:

>  Hi,
>
> I have altered isSignedCharDefault()  to make 'char' unsigned for the
> xcore target too.
> (The signedness of 'char' is an ABI issue as far a the standard is
> concerned.)
>
> My problem now is that char-bitfields are also being made unsigned.
> According to the standard the members of a bitfield are always signed
> unless explicitly marked unsigned.
>

What standard? C++ requires that bit-fields have the same signedness as
their underlying type. If 'char' is unsigned, then bit-fields of type
'char' are also unsigned.


> Hence I need:
>     'char' to be unsigned.
>     but the bit field 'char' to be signed.
>
> viz:
>     // ABI requires plain 'char' to be unsigned
>     char c = (char)-1;
>     assert(c >= 0);
>
>     // members of a bitfield are always signed unless explicitly marked
> unsigned
>     struct char_sign { char x : 1; };
>     char_sign.x = 1;
>     assert(char_sign.x < 0);
>
>
> Is this possible in clang?
> If not, could anyone like to point me in the right direction to where the
> fix would be necessary?
>
> Thank you
>
> Robert
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130730/1eb03db2/attachment.html>


More information about the cfe-dev mailing list