All of lore.kernel.org
 help / color / mirror / Atom feed
From: soraberri <421246@posta.unizar.es>
To: linux-c-programming@vger.kernel.org
Subject: Re: newby.-interpreting C
Date: Tue, 21 Dec 2004 16:39:18 +0100	[thread overview]
Message-ID: <cq9g4e$62u$1@sea.gmane.org> (raw)
In-Reply-To: <20041220211709.GD2460@lug-owl.de>

Jan-Benedict Glaw wrote:
> On Mon, 2004-12-20 20:07:54 +0100, soraberri <421246@posta.unizar.es>
> wrote in message <cq77vi$1ej$1@sea.gmane.org>:
> 
>>Hi all,
>>
>>Anyone could give me the meaning of this definition? Is the 
>>__attribute__ stuff what scares me. If you feel like I'm too 
>>desoriented, please tell me what should I know first.
>>
>>typedef struct {
>>	uint8_t b[6];
>>} __attribute__((packed)) bdaddr_t;
> 
> 
> Compilers do use __attribute__ to allow programmers to modify the
> compiler's behavior in certain areas. "packed" tells the compiler to not
> start each variable at a natural alignment (ie. 4 bytes on a 32bit
> machine, 8 bytes on a 64bit machine). (That is, the address of a given
> variable must be a multiple of 4 (or 8) bytes.)
> 
> A "packed" structure is usually used for two things:
> 
> 	- In device drivers to fit a hardware device's memory-mapped
> 	  register structure
> 	- In poorly written programs to store variables into on-disk
> 	  files to be read back later on by other programs.
> 
> General rule: if you don't *need* this for a good reason, or if you even
> don't know what it does, you don't need it, since it also introduces a
> performance penalty: CPUs tend to be fast at naturally aligned memory
> accesses, but quite slow on non-aligned accesses.
> 
> MfG, JBG
> 

All rigth, it has been very helpful, thank you very much

regards
Luis


  reply	other threads:[~2004-12-21 15:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-20 19:07 newby.-interpreting C soraberri
2004-12-20 19:38 ` Nir Dremer
2004-12-20 21:17 ` Jan-Benedict Glaw
2004-12-21 15:39   ` soraberri [this message]
2004-12-30 11:26   ` Glynn Clements
2004-12-30 11:40     ` Jan-Benedict Glaw

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='cq9g4e$62u$1@sea.gmane.org' \
    --to=421246@posta.unizar.es \
    --cc=linux-c-programming@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.