Networking Forums

Networking Forums > Computer Networking > Linux Networking > fields ordering in structure RTL instructions.

Reply
Thread Tools Display Modes

fields ordering in structure RTL instructions.

 
 
Riccardo Manfrin
Guest
Posts: n/a

 
      04-04-2011, 10:13 AM
I'm messing with the followig structure, compiling with GNU GCC on an
ARM architecture.

typedef union _waltdisney{
struct{
uint8_t goofy : 5;
uint8_t pluto : 1;
uint8_t donald : 2;
} __packed family;
uint8_t val;
} __packed waltdisney_t;

It looks like the first fields of "family" packed structure are mapped
into the less significant bits of the waltdisney_t type value. So for
instance, the following assignment

waltdisney_t wd;
wd.val = 0x0F;

is interpreted as assigning 0 to donald, 0 to pluto and 15 to goofy.Is
this always true? Can I get to know or even force the behavior for the
field ordering?

Thanks in advance.
RM




 
Reply With Quote
 
 
 
 
Tauno Voipio
Guest
Posts: n/a

 
      04-04-2011, 07:41 PM
Riccardo Manfrin wrote:
> I'm messing with the followig structure, compiling with GNU GCC on an
> ARM architecture.
>
> typedef union _waltdisney{
> struct{
> uint8_t goofy : 5;
> uint8_t pluto : 1;
> uint8_t donald : 2;
> } __packed family;
> uint8_t val;
> } __packed waltdisney_t;
>
> It looks like the first fields of "family" packed structure are mapped
> into the less significant bits of the waltdisney_t type value. So for
> instance, the following assignment
>
> waltdisney_t wd;
> wd.val = 0x0F;
>
> is interpreted as assigning 0 to donald, 0 to pluto and 15 to goofy.Is
> this always true? Can I get to know or even force the behavior for the
> field ordering?
>
> Thanks in advance.
> RM



There is even no guarantee of byte ordering
in ARM cores. There is a signal between the
core and the surrounding chip selecting the
byte ordering. It depends on the whim of the
chip designer how the signal is connected.

You will invite problems later on if you
trust a probed packing ordering.

The way of setting up a packed structure is
an implementation-defined part in the C standard.

A better way would be to define bit masks
and pick the bits by hand, if you're trying
to match hardware-defined bit fields.

What are you attempting to achieve?

--

Tauno Voipio
tauno voipio (at) iki fi

 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a

 
      04-04-2011, 09:56 PM
On Mon, 2011-04-04, Riccardo Manfrin wrote:
> I'm messing with the followig structure, compiling with GNU GCC on an
> ARM architecture.
>
> typedef union _waltdisney{
> struct{
> uint8_t goofy : 5;
> uint8_t pluto : 1;
> uint8_t donald : 2;
> } __packed family;
> uint8_t val;
> } __packed waltdisney_t;


Which version of gcc is this? My documentation for gcc 4.4 doesn't
mention "__packed", except perhaps in combination with __attribute__.
And it doesn't compile:

salix:~% gcc -c /tmp/q.c
/tmp/q.c:8: error: expected ':', ',', ';', '}' or '__attribute__' before 'family'
/tmp/q.c:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'waltdisney_t'
/tmp/q.c:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'foo'

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Riccardo Manfrin
Guest
Posts: n/a

 
      04-06-2011, 08:42 AM
> A better way would be to define bit masks
> and pick the bits by hand, if you're trying
> to match hardware-defined bit fields.
>
> What are you attempting to achieve?


bit masking is definitely the cleaner way, but I'd like to have a
simple yet flexible way to frame the bits, just like the reported data
structure shows.
I found some workaround which seem to work quite well and whose I'll
be posting of soon (as soon as I have time to)..
Thanks in advance
 
Reply With Quote
 
Riccardo Manfrin
Guest
Posts: n/a

 
      04-06-2011, 08:43 AM

> Which version of gcc is this? My documentation for gcc 4.4 doesn't
> mention "__packed", except perhaps in combination with __attribute__.
> And it doesn't compile:


Sorry, __packed is my define for __attibute__ (( packed ))



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mark skb priority fields Viks Linux Networking 0 05-19-2008 10:34 AM
Which News-fields are needed ? news@absamail.co.za Linux Networking 1 12-19-2005 11:22 AM
can electrical fields block wireless transfer? Rob B Wireless Networks 2 11-14-2005 10:03 PM
MN-500 Persistant Port Forwarding - Need More Fields! Me I Myself Broadband Hardware 6 01-22-2004 01:16 PM
IP adress fields do not accept data in TCP/IP Properties Harry Windows Networking 4 09-20-2003 07:40 AM



1 2 3 4 5 6 7 8 9 10 11