* newby.-interpreting C
@ 2004-12-20 19:07 soraberri
2004-12-20 19:38 ` Nir Dremer
2004-12-20 21:17 ` Jan-Benedict Glaw
0 siblings, 2 replies; 6+ messages in thread
From: soraberri @ 2004-12-20 19:07 UTC (permalink / raw)
To: linux-c-programming
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;
thanks very much
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: newby.-interpreting C
2004-12-20 19:07 newby.-interpreting C soraberri
@ 2004-12-20 19:38 ` Nir Dremer
2004-12-20 21:17 ` Jan-Benedict Glaw
1 sibling, 0 replies; 6+ messages in thread
From: Nir Dremer @ 2004-12-20 19:38 UTC (permalink / raw)
To: soraberri; +Cc: linux-c-programming
this specific attributes is intended in order to avoid structure
alignment in memory.
The compiler is performing alignment to any allocation to be a
multiplication of 4k.
in order to disable this alignment __attribute__ packed is being used.
usually this is being used when working with networking:
if you have a structure of 5k and you will send it you will actually
send 8k.
attributes information:
http://www.unixwiz.net/techtips/gnu-c-attributes.html
cheers
On Mon, 2004-12-20 at 20:07 +0100, soraberri wrote:
> 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;
>
> thanks very much
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: newby.-interpreting C
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
2004-12-30 11:26 ` Glynn Clements
1 sibling, 2 replies; 6+ messages in thread
From: Jan-Benedict Glaw @ 2004-12-20 21:17 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1607 bytes --]
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
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: newby.-interpreting C
2004-12-20 21:17 ` Jan-Benedict Glaw
@ 2004-12-21 15:39 ` soraberri
2004-12-30 11:26 ` Glynn Clements
1 sibling, 0 replies; 6+ messages in thread
From: soraberri @ 2004-12-21 15:39 UTC (permalink / raw)
To: linux-c-programming
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: newby.-interpreting C
2004-12-20 21:17 ` Jan-Benedict Glaw
2004-12-21 15:39 ` soraberri
@ 2004-12-30 11:26 ` Glynn Clements
2004-12-30 11:40 ` Jan-Benedict Glaw
1 sibling, 1 reply; 6+ messages in thread
From: Glynn Clements @ 2004-12-30 11:26 UTC (permalink / raw)
To: linux-c-programming
Jan-Benedict Glaw wrote:
> 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.
On most processor types, unaligned accesses will fail (either generate
an exception or return bogus data). The x86 family is the exception,
in that unaligned access merely reduces performance.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: newby.-interpreting C
2004-12-30 11:26 ` Glynn Clements
@ 2004-12-30 11:40 ` Jan-Benedict Glaw
0 siblings, 0 replies; 6+ messages in thread
From: Jan-Benedict Glaw @ 2004-12-30 11:40 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1029 bytes --]
On Thu, 2004-12-30 11:26:08 +0000, Glynn Clements <glynn@gclements.plus.com>
wrote in message <16851.58832.659413.893211@gargle.gargle.HOWL>:
> Jan-Benedict Glaw wrote:
>
> > 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.
>
> On most processor types, unaligned accesses will fail (either generate
> an exception or return bogus data). The x86 family is the exception,
> in that unaligned access merely reduces performance.
As is the VAX :)
MfG, JBG
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-12-30 11:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2004-12-30 11:26 ` Glynn Clements
2004-12-30 11:40 ` Jan-Benedict Glaw
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 NNTP newsgroup(s).