<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi Richard,<br>
<br>
<div>> 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.</div>
Sorry, I was thinking of the C99 standard.<br>
But I actually was half quoting c++ 2011 standard.<br>
Either way, I was wrong - but still not clear.<br>
<br>
The XCore ABI (currently implemented by the XCore llvm-gcc frontend) expects:<br>
'char' to be unsigned.<br>
but the bit field 'char' to be signed.<br>
<br>
Does this infringe the C99 & C++11 standards?<br>
I'll keep reading but I'm no lawyer.<br>
<br>
robert<br>
<br>
C++<br>
9.6:p3<br>
It is implementation-defined whether a plain (neither explicitly signed nor unsigned) char, short, int or long bit-field is signed or unsigned.<br>
<br>
C99<br>
6.2.5:p15<br>
The three types char, signed char, and unsigned char are collectively called the character types. The implementation shall define char to have the same range, representation, and behavior as either signed char or unsigned char.<br>
6.7.2:p5<br>
Each of the comma-separated sets designates the same type, except that for bit-fields, it is implementation-defined whether the specifier int designates the same type as signed int or the same type as unsigned int.<br>
6.7.2.1:p9<br>
A bit-field is interpreted as a signed or unsigned integer type consisting of the specified number of bits. 105<br>
105) As specified in 6.7.2 above, if the actual type specifier used is int or a typedef-name defined as int, then it is implementation-defined whether the bit-field is signed or unsigned.<br>
<br>
<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF160355"><font color="#000000" face="Tahoma" size="2"><b>From:</b> metafoo@gmail.com [metafoo@gmail.com] on behalf of Richard Smith [richard@metafoo.co.uk]<br>
<b>Sent:</b> 30 July 2013 19:19<br>
<b>To:</b> Robert Lytton<br>
<b>Cc:</b> cfe-dev@cs.uiuc.edu; benny.kra@gmail.com<br>
<b>Subject:</b> Re: [cfe-dev] different signedness for bitfield 'char' and plain 'char'<br>
</font><br>
</div>
<div></div>
<div>On Tue, Jul 30, 2013 at 10:51 AM, Robert Lytton <span dir="ltr"><<a href="mailto:robert@xmos.com" target="_blank">robert@xmos.com</a>></span> wrote:<br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div>
<div style="direction:ltr; font-size:10pt; font-family:Tahoma">Hi,<br>
<br>
I have altered<font> <span style="font-size:10pt"><font><span style="font-size:10pt"></span></font>isSignedCharDefault() to make 'char' unsigned for the xcore target too.<br>
(The signedness of 'char' is an ABI issue as far a the standard is concerned.)<br>
<br>
</span></font>My problem now is that char-bitfields are also being made unsigned.<br>
According to the standard the members of a bitfield are always signed unless explicitly marked unsigned.<br>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>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.</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div>
<div style="direction:ltr; font-size:10pt; font-family:Tahoma">Hence I need:<br>
'char' to be unsigned.<br>
but the bit field 'char' to be signed.<br>
<br>
viz:<br>
// ABI requires plain 'char' to be unsigned<br>
char c = (char)-1;<br>
assert(c >= 0);<br>
<br>
// members of a bitfield are always signed unless explicitly marked unsigned<br>
struct char_sign { char x : 1; };<br>
char_sign.x = 1;<br>
assert(char_sign.x < 0);<br>
<br>
<br>
Is this possible in clang?<br>
If not, could anyone like to point me in the right direction to where the fix would be necessary?<br>
<br>
Thank you<span class="HOEnZb"><font color="#888888"><br>
<br>
Robert<br>
<br>
<br>
</font></span></div>
</div>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</body>
</html>