[Icc-avr] Casting
Albert vanVeen
Albert.vanVeen at pertronic.co.nz
Mon Jan 14 12:51:15 PST 2008
Some compilers have operators like "high()" and "low()", which makes it
clear to the compiler (and to the reader) that that is exactly the
simple thing that you want: just use the appropriate address and no
superfluous instructions.
Albert.
-----Original Message-----
From: icc-avr-bounces at imagecraft.com
[mailto:icc-avr-bounces at imagecraft.com] On Behalf Of Johannes Assenbaum
Sent: Tuesday, January 15, 2008 08:41 AM
To: icc-avr at imagecraft.com
Subject: Re: [Icc-avr] Casting
As someone mentioned before, this is only safe for Little Endian, but as
AVRs are Little Endian, there will be no problem with iccavr.
Btw: Shortest code (no optimisation enabled) will be with source value
casted.
Data[7] = ((unsigned int)(Channel_One) >> 8); Data[8] = ((unsigned
int)(Channel_One));
Best regards,
Johannes
>> 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);
>>>
> I always use the above solution, it should be perfectly legal and it
> has never failed me on any compiler. I think it is quite clear for any
> programmer of embedded systems what this does.
> regards
> Johan
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.516 / Virus Database: 269.19.2/1223 - Release Date:
> 13.01.08 20:23
_______________________________________________
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