public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to change bit-field allocation
@ 2004-09-06 11:41 Min ZOU
  2004-09-06 17:15 ` Ramana Radhakrishnan
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Min ZOU @ 2004-09-06 11:41 UTC (permalink / raw)
  To: gcc

HI,

As I know, GCC allocates bit-fields inside a structure from the lowest
addressed byte, i.e. LSB, for little endian. However, I want to reverse
the ordering for the bit-fields allocation, i.e. always from MSB.

How to achieve this in GCC?

Thanks!

-- 
Best Regards

Min

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: How to change bit-field allocation
@ 2004-09-07 14:59 Etienne Lorrain
  0 siblings, 0 replies; 11+ messages in thread
From: Etienne Lorrain @ 2004-09-07 14:59 UTC (permalink / raw)
  To: gcc

Min ZOU wrote:
> Robert Dewar wrote:
> > I guess that the problem is that he wants a magical way of dealing with
> > endian differences between processors. Many people want this, but
> > unfortunately there is no coherent consistent way of doing this.
> > This topic has been much studied and discussed in the Ada world :-)
>
> The problem is not due to endian differences but compiler differences. I >
came across this problem when I have to combine two binary images while
> are compiled by different compilers: one by GCC, the other by SH
> proprietary compiler. However the bit-field's members are allocated from
> the lower bit in GCC, while from higher bit in SH compiler.

  I had the impression that only one logical way was possible depending
 on the processor, so that:

union {
  unsigned char val1;
  unsigned      val2 : 8;
  unsigned char val3[1];
  struct { unsigned char c1, c2; } val3;
  ... whatever ...
  } a_union;

 the value of "a_union.val1", "a_union.val2",  "a_union.val3[0]" and
 "a_union.val3.c1" are identical - assuming 8 bits chars.

  Same for (assuming 16 bits shorts):
union {
  unsigned short val1;
  unsigned       val2 : 16;
  enum { e1, e2, e3 } val3 : 16;
  } union2;

  Etienne.


	

	
		
Vous manquez dÂ’espace pour stocker vos mails ? 
Yahoo! Mail vous offre GRATUITEMENT 100 Mo !
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/

Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis. A télécharger gratuitement sur http://fr.messenger.yahoo.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-09-13  7:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-06 11:41 How to change bit-field allocation Min ZOU
2004-09-06 17:15 ` Ramana Radhakrishnan
2004-09-06 21:43 ` James E Wilson
2004-09-06 22:19   ` Robert Dewar
2004-09-07  3:44     ` Min ZOU
2004-09-07 15:56   ` Dave Korn
2004-09-13  9:09   ` tm_gccmail
2004-09-07  1:24 ` DJ Delorie
2004-09-07  3:47   ` Min ZOU
2004-09-07 14:07     ` Robert Dewar
2004-09-07 14:59 Etienne Lorrain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).