[Icc-avr] Casting
Jaspers, Ton
t.jaspers at cpseurope.com
Tue Jan 15 00:29:31 PST 2008
> -----Original Message-----
> From: Johannes Assenbaum
>
> 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));
True if you never re-use your code and if your application
has no links with the rest of the world whatsoever.
However, it is not uncommon when an embedded engineering
company works with several different CPU's in one project
and tries to re-use standard code parts. In my case I work,
in average, on two CPU's at a time and sometimes more. At
this very moment I work on a project with a Freescale-
Coldfire as main CPU and an AVR front-end to handle the
keypad and receive the IR Commands from a remote control.
Also, today, most systems are interfaced with other systems
one way or another. An AVR may be connected to a big endian
CPU through I2C for example, or we need to deal with data
from the Internet. With that in mind it pays to program
your conversions endian independent. With a bit of
discipline a lot of small problems are avoided, problems
that often need significants amount of time to find and
solve. Except from a single source file called hal.c
(hardware abstraction layer) I really don't want to know
for what type of CPU I am programming.
There is no excuse for sloppy programming.
Cheers,
Ton
More information about the Icc-avr
mailing list