public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Der Herr Hofrat <der.herr@mail.hofr.at>
To: eddy@fericom.net
Cc: gcc-help@gcc.gnu.org
Subject: Re: Bitfield packing
Date: Sat, 17 Aug 2002 11:58:00 -0000	[thread overview]
Message-ID: <200208171802.g7HI2wN24657@hofr.at> (raw)
In-Reply-To: <20020817073337.GA816@fericom.net> from "eddy@fericom.net" at "Aug 17, 2002 09:33:37 am"

> Hi, 
> 
> I am using gcc for a microcontroller application. I want to use
> bitfields to describe the processor registers, 
> similar to this: 
> 
> typedef union {
> 	IO_BYTE byte; 
> 	struct {
> 		IO_BYTE P30 :1; 
> 		IO_BYTE P31 :1; 
> 		IO_BYTE P32 :1; 
> 		IO_BYTE P33 :1; 
> 		IO_BYTE P34 :1; 
> 		IO_BYTE P35 :1; 
> 		IO_BYTE P36 :1; 
> 		IO_BYTE P37 :1; 
> 	} bit; 
> } PDR2;
> 
> How does gcc handle bitfields like thisone? Above I have defined 8 bits,
> are they distributed on several bytes with some optimization levels?

if you don't use any __attribute__((packed)) on the bitfields the size of
this object will be alligned machin dependant (probably 32bit on a 32bit box)
you can see that by using the __alignof__() (just like sizeof) function to
report allignement - internal ordering I guess is nothing you should ever 
relie on. See the section "storage layout" in the gcc manual for infos on
what may influence your setup (i.e. BITS_PER_UNIT).

If you want to be shure of the bit-positions I guess you must use 
bit-operators and allocate an unsigned char / u8 object.

hofrat

      reply	other threads:[~2002-08-17 18:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-17  2:33 eddy
2002-08-17 11:58 ` Der Herr Hofrat [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200208171802.g7HI2wN24657@hofr.at \
    --to=der.herr@mail.hofr.at \
    --cc=eddy@fericom.net \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).