avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] casting problems?


From: Rolf Magnus
Subject: Re: [avr-chat] casting problems?
Date: Thu, 27 Apr 2006 18:52:21 +0200
User-agent: KMail/1.9.1

On Thursday 27 April 2006 17:32, Steve Franks wrote:
> Hi all,
>
> Anybody care to take a stab at why:
>
> #include <stdint.h>
> __inline__ void rx_addr(uint8_t a){tx( (uint8_t)(0x40) | a );}
>
> Gives me:
>
> C:/projects/include/test.hpp:84: error: call of overloaded `tx(int)' is
> ambiguous

Integer promotion. your (uint8_t)(0x40) and 'a' both get promoted to int 
before the 'or' operator is used on them. The result is of course of type 
int, too.

> Given that I have both:
>
> void tx(uint16_t)
> void tx(uint8_t)
>
> defined in test.hpp.
>
> I think the problems started with the upgrade from winavr 2005 to winavr
> 2006.
>
> Also, if I change to:
>
> __inline__ void rx_addr(uint8_t a){tx( (uint8_t)(0x0040 | (uint16_t)(a))
> );}
>
> The project builds, and tx(uint8_t) is called correctly, but from using the
> debugger, I have discovered that the 0x10 I pass in goes out to tx() as
> 0x10, not 0x50 like it should be.

Hmm, no idea why it's doing that.

>
> I have built with both -Os and -O0, so it's not an optimization issue (why
> do we always blame the optimizer ;)

Well, sometimes, things get optimized away because they are not needed for the 
program to be executed correctly. But in the debugger, it can look wrong. 
This, in connnection with a real error, can drive you crazy.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]