Re: [cc65] Another bug... ?

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2002-07-18 16:30:03


Hi!

On Thu, Jul 18, 2002 at 04:05:03PM +0200, groepaz wrote:
> look at this, problem is a case value of "0x8000" (min_int) used in a
> switch statement where the switch is done by a signed int. (mmmh and
> its weird to me that 0x8000 and -32768 are threated differently ...
> sth with signed vs unsigned conversion looks fux0red here.....0xffff
> vs -1 shouldnt make a difference at this point either eh?)

Hex constants and decimal constants are handled differently according to the C
standard:

  - For a decimal constant, the valid types are int, long and unsigned long.

  - A hexadecimal constant may also be represented as an unsigned.

This means that:

  0xFFFF        is an unsigned with a value of 65535 decimal
  0x8000        is an unsigned with a value of 32768 decimal
  -32768        is an int
  -1            is also an int

So the only thing that is wrong with the code is the warning "constant is
long". The other errors are correct, because a 16 bit integer can never be one
of { 32768, 65535 }. I'm currently not sure if the compiler should do any
conversions here (I will have to check the standard), but even if it does, the
results would be implementation defined and therefore not portable.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2002-07-18 16:30:55 CEST