[Icc-avr] Casting

Albert vanVeen Albert.vanVeen at pertronic.co.nz
Sun Jan 13 11:17:19 PST 2008


I've always used the first (simplest) solution, and an occasional look
at the assembly code looked perfectly alright, i.e. as expected.
Unless it is really necessary, casting doesn't help for readability,
does it?
But you might say: better safe than sorry.
In any case, a quick check of the final code shows you if there's any
danger.

Albert.


-----Original Message-----
From: icc-avr-bounces at imagecraft.com
[mailto:icc-avr-bounces at imagecraft.com] On Behalf Of John Baraclough
Sent: Sunday, January 13, 2008 04:39 AM
To: Discussion list for ICCAVR and ICCtiny Users. You do NOT need
tosubscribe to icc-announce if you are a member of this.
Subject: Re: [Icc-avr] Casting

Andrew wrote:
> Hi,
>
> When casting and int to two char' (a MSB and LSB) is it safe to do the
> following:-
> Data[7] = (Channel_One >> 8);
> Data[8] = (Channel_One);
>
No
> Or am i best doing: -
>
> Data[7] = ((unsinged char)Channel_One >> 8); Data[8] = ((unsinged 
> Char)Channel_One);
>
Yes, but you need to adjust your parentheses and spelling.
> or
>
> Data[7] = (((unsigned char)(Channel_One & 0xF0)) >> 8 ); Data[8] = 
> (Channel_One & 0x0F);
>
No, because Data[7] will always be 0 and Data[8] should be cast and will
have a maximum value of 15.
>
>
> Andy
>
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
>
>
HTH

John

_______________________________________________
Icc-avr mailing list
Icc-avr at imagecraft.com
http://dragonsgate.net/mailman/listinfo/icc-avr

Scanned by Bizo Email Filter




More information about the Icc-avr mailing list