Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > does 0<(unsigned short)0x8000 hold?

Reply
Thread Tools

does 0<(unsigned short)0x8000 hold?

 
 
Philipp Klaus Krause
Guest
Posts: n/a
 
      03-28-2012
On 27.03.2012 16:32, Francois Grieu wrote:
> I just tested my code for portability problems on systems
> where int is 16-bit, and found one such system where []


Which system?

Philipp
 
Reply With Quote
 
 
 
 
Francois Grieu
Guest
Posts: n/a
 
      03-28-2012
On 27/03/2012 19:32, Tim Rentsch wrote:
> Francois Grieu <(E-Mail Removed)> writes:
>
>> I just tested my code for portability problems on systems
>> where int is 16-bit, and found one such system where
>>
>> #include <stdio.h>
>> int main(void)
>> {
>> printf("%d\n", 0<(unsigned short)0x8000 );
>> return 0;
>> }
>>
>> outputs 0. If I change 0< to 0u<, the output is 1.
>>
>> Is that a bug in this compiler, w.r.t. C99?

>
> Yes. There is a simple argument that it is:
>
> 1. The value 0x8000 is always representable as an unsigned short.
>
> 2. The rules for 'integer promotions' always preserve value.
>
> 3. The rules for 'usual arithmetic conversions' preserve value
> for all operand values that are non-negative. (A negative
> operand value might become non-negative due to UAC, but
> all non-negative values don't change under UAC.)
>
> Since 0 < 0x8000 must hold, 0 < (unsigned short) 0x8000 must hold,
> because ultimately the same mathematical comparison is done.


Nice, reusable argument. Thanks.

>
>
>> As an aside, 6.5.8p2 puzzles me; [snip]
>>
>> As an aside of the aside, I do not understand the third option in
>> the constraint, and it has been removed in N1570.

>
> The removal is not a change but just indicative of a change in
> nomenclature. In C99, there are incomplete types and object
> types. In N1570, there are incomplete object types and complete
> object types, which together make up object types. So in N1570,
> both complete and incomplete types are included under the now
> more general 'object type' term, and hence the third option in
> C99 is folded into the second option in N1570.


Again, thanks for the synthetic explanation.

Francois Grieu
 
Reply With Quote
 
 
 
 
Francois Grieu
Guest
Posts: n/a
 
      03-28-2012
On 28/03/2012 09:07, Philipp Klaus Krause wrote:
> On 27.03.2012 16:32, Francois Grieu wrote:
>> I just tested my code for portability problems on systems
>> where int is 16-bit, and found one such system where []

>
> Which system?


The CPU was a regular PC, running cmd.exe of Windows XP SP3; the
failing compiler was Turbo C++ 1.01 (released 1991) in C mode.
I am NOT using that compiler for anything but test.
I there is a more modern 80x86 16-bit compiler (defined as
UINT_MAX==0xFFFF, perhaps as an option), I want to know.

My usual 16-bit targets include
- ST7/ST19/ST21/ST23
- PIC18
- 8051 and derivatives
and (at least with the compilers I now use for production)
pass this test.

My customer's platform include
- 68K derivatives (including ColdFire)
- ARM derivatives
- MIPS derivatives
- 80x86 derivatives
For some of my customer's target systems, the option exist
to compile with a 16-bit int (e.g. gcc -mshort ), and I have
no idea of my customer's choice.

Francois Grieu
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      03-28-2012
On 2012-03-28, Francois Grieu <(E-Mail Removed)> wrote:
> On 28/03/2012 09:07, Philipp Klaus Krause wrote:
>> On 27.03.2012 16:32, Francois Grieu wrote:
>>> I just tested my code for portability problems on systems
>>> where int is 16-bit, and found one such system where […]

>>
>> Which system?

>
> The CPU was a regular PC, running cmd.exe of Windows XP SP3; the
> failing compiler was Turbo C++ 1.01 (released 1991) in C mode.


Hahaha, you wasted everyone's time answering questions about
irrelevant old cruft. Good job!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET 2.0 ASPx Page does not load, but HTM does prabhupr@hotmail.com ASP .Net 1 02-08-2006 12:57 PM
Button OnClick does not fire on first postback, but does on second Janet Collins ASP .Net 0 01-13-2006 10:08 PM
Does the 2.0 Framework come out when Visual Studio .NET 2005 does? needin4mation@gmail.com ASP .Net 3 10-07-2005 12:55 AM
CS0234 Global does not exist ... but it genuinely does Bill Johnson ASP .Net 0 07-08-2005 06:34 PM
Does no one else think microsoft does a poor job? =?Utf-8?B?SmVyZW15IEx1bmRncmVu?= Wireless Networking 2 11-20-2004 12:17 AM



Advertisments