paparazzi-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: X-IMail-SPAM-Connection Re: [Paparazzi-devel] I need an expert in C


From: Brad Douglas
Subject: Re: X-IMail-SPAM-Connection Re: [Paparazzi-devel] I need an expert in C
Date: Fri, 04 Sep 2009 14:15:12 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.1) Gecko/20090814 Fedora/3.0-2.6.b3.fc11 Thunderbird/3.0b3

Also, with modern C compilers you can also specify bit length within the structure, itself:

struct dummy
{
        unsigned int    booleanA        : 1;
        unsigned int    booleanB        : 2;
        unsigned int    fourbits        : 4;
};

URL reference:
http://en.wikipedia.org/wiki/Bit_field

On 09/04/2009 12:31 AM, Michele Santucci wrote:
Hallo Cédric,

if I understood your problem the workaround could be a compiler directive to 
override the
default  compiler memory aligment policy, of course this directive is strongly 
bound to the
compiler itself but it usually sounds like a 'pragma' directive i.e. #pragma 
option push -a1,
#pragma pack(1). Anyway look into compiler manual and you will find this 
information easily.



From: Cédric Marzer
Sent: Friday, September 04, 2009 8:47 AM
To: address@hidden
Subject: [Paparazzi-devel] I need an expert in C


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.


--
73, de KB8UYR/6 Brad Douglas <address@hidden>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]