[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Paparazzi-devel] I need an expert in C
From: |
Famille Chateauvieux-Hellwig |
Subject: |
Re: [Paparazzi-devel] I need an expert in C |
Date: |
Fri, 4 Sep 2009 18:47:29 +0200 |
User-agent: |
KMail/1.11.2 (Linux/2.6.28-15-generic; KDE/4.2.2; x86_64; ; ) |
Hi Cédric,
What compiler are you using? With GCC you can say:
struct test_t {
int a;
char b;
int c;
} __attribute__((__packed__));
If you can choose the order in which the items are placed in the structure,
put the biggest at the front, and the shortest at the back.
typedef struct {
long l;
long l2;
short s1;
char c1;
char c2;
} naturally_packed_t
Regards
Martial
Le vendredi 4 septembre 2009 08:47:41 Cédric Marzer, vous avez écrit :
> Hello,
>
>
>
> My OSD makes good progress but I am stuck with some C trick.
>
> The messages are stored in an array each char, short or long following each
> other.
>
> I want to map this message into different structures (for the gps message,
> the batterie message, etc.).
>
>
>
> The crude way to do that (it works), is the following :
>
> gps.utm_north=MAKE32(array[12],array[11],array[10],array[9];
>
> etc.
>
> But that means that I will write a dozen of this for each message
>
>
>
> The (not so smart) way is to do that :
>
>
>
> gpspointer=&array+4
>
>
>
> but there is a trap
>
> When you make a structure, the compiler makes sure that the short and long
> are aligned in the memory
>
> and add gaps after let's say a char to make sure that the next long is well
> aligned in the memory.
>
> That means that the data in my array and in the structure are not aligned.
> The process to put the gaps is called "padding".
>
>
>
> Some compiler and processor allow one to disable "padding". I doubt that
> this is the case with arm.
>
>
>
> So does anyone of you have a smart idea for a clean work around ? Otherwise
> I will just go the crude way
>
>
>
> Cheers
>
>
>
> Cédric
Re: [Paparazzi-devel] I need an expert in C,
Famille Chateauvieux-Hellwig <=