[fpc-devel] Freepascal in microcontrollers

Vinzent Hoefler JeLlyFish.software at gmx.net
Wed Feb 27 15:44:45 CET 2008

On Wednesday 27 February 2008 14:15, Florian Klaempfl wrote:
> Vinzent Hoefler schrieb:
> > And that's why I'd rather go with Ada's representation clauses. If
> > the hardware platform is unsuitable for the thing I want it to do,
> > it simply doesn't compile. Which is justified, because in 99% of
> > the times such RCs are hardware specific.
> I still don't see how ada could handle things like little endian cpus
> accessing big endian peripherial with bit patterns overlapping byte
> borders (no, this is not an academic case, just look at the brain
> dead arm fpa).

Well, I'm not sure what you want here, let me try:

|type Data is ...
|for Data'Bit_Order use High_Order_First;
|for Data use
|  record
|     Byte_3 at 0 range 0 .. 7;
|     Byte_2 at 1 range 0 .. 7;
|     Byte_1 at 2 range 0 .. 7;
|     Byte_0 at 3 range 0 .. 7;
|  end record;

Don't get it wrong. An Ada compiler does *not* automatically flip bytes 
for you, so if you really have some type spanning byte boundaries in 
the wrong endianess, you still have to flip it accordingly. IOW:

|type Data is:
|for Data'Bit_Order use High_Order_First;
|for Data use
|  record
|     Word_1 at 0 range 0 .. 15;
|     Word_0 at 2 range 0 .. 15;

does not work as one might expect. The bytes would still be flipped on a 
little endian machine.

But at least it is possible to define a record representation totally 
endianess independent. It's a bit more complex than necessary, so it's 
probably better to read the whole stuff (although it might require some 
Ada experience to really see it through)


instead of letting me give you an example.

After all, for embedded programming the guarantees I get from Ada record 
representation clauses is usually enough to know it'll work.


More information about the fpc-devel mailing list