<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 04/17/2013 07:46 PM, Joel Sherrill
wrote:<br>
</div>
<blockquote cite="mid:516EDFE7.5050103@oarcorp.com" type="cite">
<meta http-equiv="Context-Type" content="text/html;
charset=ISO-8859-1">
<div class="moz-cite-prefix">On 4/17/2013 10:15 AM, Ralf Corsepius
wrote:<br>
</div>
<blockquote cite="mid:516EBC76.1060608@rtems.org" type="cite">
<pre wrap="">On 04/17/2013 02:53 PM, Sebastian Huber wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On 04/17/2013 12:19 PM, Ralf Corsepius wrote:
[...]
</pre>
<blockquote type="cite">
<pre wrap="">@@ -147,8 +147,8 @@ static uint32_t simple_random(uint32_t v)
static unsigned get_bucket_with_random(unsigned count, long random)
{
- long unsigned unit = (1U << 31) / count;
- long unsigned bucket = (long unsigned) random / unit;
+ uint32_t unit = ((uint32_t) 1U << 31) / count;
+ uint32_t bucket = (uint32_t) random / unit;
if (bucket != count) {
return bucket;
</pre>
</blockquote>
<pre wrap="">A long must be able to store a 32-bit integer so there is no need to use
uint32_t here.
</pre>
</blockquote>
<pre wrap="">Such is theory - Realty is different.
The assumptions of long >= 32 bit only applies to POSIX conformant targets.
</pre>
</blockquote>
According to Wikipedia, C99 requires long to be >= 32 bits<br>
<a moz-do-not-send="true"
href="http://en.wikipedia.org/wiki/C_data_types">(http://en.wikipedia.org/wiki/C_data_types</a>)
which matches<br>
the definition of LONG_MIN/LONG_MAX in limits.h per this<br>
admittedly draft from 2005 TC3 version of the standard <br>
<br>
<a moz-do-not-send="true"
href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf">http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf</a><br>
<br>
It appears this is the last draft before final vote.<br>
<blockquote cite="mid:516EBC76.1060608@rtems.org" type="cite">
<pre wrap="">RTEMS however supports targets, which are not strictly POSIX compliant,
where longs are 16bit => The code above fails to compile the code above
when using longs.
</pre>
</blockquote>
I tried the h8300 multilibs and got sizeof(long)==4. I recall
cases where there <br>
were warnings when int overflowed when << by more than 16
bits. But that's<br>
reasonable. int can be 16 bits and we have third party code that
primarily <br>
supports 32-bit environments. That leaves this question:<br>
<br>
Which target and multilib has long < 32-bits? <br>
</blockquote>
You've got me, the issue isn't long, it's int.<br>
<br>
The code in question fails to build for the h8300/sx due to implicit
typecasts on 16bit ints.<br>
<br>
Ralf<br>
<br>
</body>
</html>