* Does __attribute__((__packed__)) aplies to types or variables?
@ 2015-10-21 17:56 Daniel.
[not found] ` <CAK7N6vrh05XDwa_nBTmid8QZUU8wgFhm0w=R+aMA9tOugL46Mg@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Daniel. @ 2015-10-21 17:56 UTC (permalink / raw)
To: linux-c-programming@vger.kernel.org
Suppose that I have a declaration:
struct __attribute__((__packed__)) foo {
char ch;
int number;
};
Will be any variable of this type be packed?
The real world thing is: I have a code that come up from 8bit world,
with a lot of lots of chained structures that are transferred throght
some radio frequence module, I need be sure that all this structs have
no padding so that they can be transferred as they are to radio. To
achieve this I've
putted __attribute__((__packed__)) to every struct and inner struct
that are sended through RF,
but I read at some StackOverflow post that packed attribute aplies to
variables not to types,
so I came here ask to experts. Is that true?
At gcc manual I found Type Attributes and Variable attributes, so I'm
assuming both exists how differentiate from one to another?
Regards,
--
"Do or do not. There is no try"
Yoda Master
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Does __attribute__((__packed__)) aplies to types or variables?
[not found] ` <CAF3SDA7pObzwzk-AzdO38-c45VggTJJpwdNzujAuyMV=eSCc=w@mail.gmail.com>
@ 2015-10-22 16:18 ` Daniel.
2015-10-24 0:52 ` Phil Sutter
0 siblings, 1 reply; 3+ messages in thread
From: Daniel. @ 2015-10-22 16:18 UTC (permalink / raw)
Cc: linux-c-programming@vger.kernel.org
I mean that packed attribute is applied only when allocation is
implied or can I apply packed
attribute to struct definitions where no variables are declared?
struct __attribute__((__packed__)) foo { ... };
struct foo bar; <--- is this packed?
Regards,
2015-10-22 14:18 GMT-02:00 Daniel. <danielhilst@gmail.com>:
> I mean that packed attribute is applied only when allocation is implied or
> can I apply packed
> attribute to struct definitions where no variables are declared?
>
> struct __attribute__((__packed__)) foo { ... };
> struct foo bar; <--- is this packed?
>
> Regards,
>
> 2015-10-21 17:17 GMT-02:00 anish singh <anish198519851985@gmail.com>:
>>
>>
>>
>> On Wed, Oct 21, 2015 at 10:56 AM, Daniel. <danielhilst@gmail.com> wrote:
>>>
>>> Suppose that I have a declaration:
>>>
>>> struct __attribute__((__packed__)) foo {
>>> char ch;
>>> int number;
>>> };
>>>
>>> Will be any variable of this type be packed?
>>>
>>> The real world thing is: I have a code that come up from 8bit world,
>>> with a lot of lots of chained structures that are transferred throght
>>> some radio frequence module, I need be sure that all this structs have
>>> no padding so that they can be transferred as they are to radio. To
>>> achieve this I've
>>> putted __attribute__((__packed__)) to every struct and inner struct
>>> that are sended through RF,
>>> but I read at some StackOverflow post that packed attribute aplies to
>>> variables not to types,
>>
>>
>> Can you elaborate? AFAIK you can safely use packed attribute to pack
>> your structures and send it over the network as long as you take care of
>> endianess.
>>
>> What do you mean by packed attribute applies to variables not to types?
>>>
>>> so I came here ask to experts. Is that true?
>>>
>>> At gcc manual I found Type Attributes and Variable attributes, so I'm
>>> assuming both exists how differentiate from one to another?
>>>
>>> Regards,
>>>
>>> --
>>> "Do or do not. There is no try"
>>> Yoda Master
>>> --
>>> 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
>>
>>
>
>
>
> --
> "Do or do not. There is no try"
> Yoda Master
--
"Do or do not. There is no try"
Yoda Master
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Does __attribute__((__packed__)) aplies to types or variables?
2015-10-22 16:18 ` Daniel.
@ 2015-10-24 0:52 ` Phil Sutter
0 siblings, 0 replies; 3+ messages in thread
From: Phil Sutter @ 2015-10-24 0:52 UTC (permalink / raw)
To: Daniel.; +Cc: linux-c-programming
On Thu, Oct 22, 2015 at 02:18:47PM -0200, Daniel. wrote:
> I mean that packed attribute is applied only when allocation is
> implied or can I apply packed
> attribute to struct definitions where no variables are declared?
Yes, it applies to the type.
> struct __attribute__((__packed__)) foo { ... };
> struct foo bar; <--- is this packed?
Compare sizeof(struct foo) with sizeof(bar) to find out yourself.
Cheers, Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-10-24 0:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-21 17:56 Does __attribute__((__packed__)) aplies to types or variables? Daniel.
[not found] ` <CAK7N6vrh05XDwa_nBTmid8QZUU8wgFhm0w=R+aMA9tOugL46Mg@mail.gmail.com>
[not found] ` <CAF3SDA7pObzwzk-AzdO38-c45VggTJJpwdNzujAuyMV=eSCc=w@mail.gmail.com>
2015-10-22 16:18 ` Daniel.
2015-10-24 0:52 ` Phil Sutter
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).