public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
* Padding in gcc
@ 2007-07-09 11:40 Rajat Jain
  2007-07-09 14:38 ` pradeep singh
  2007-07-10 20:15 ` Rodrigo Rubira Branco
  0 siblings, 2 replies; 5+ messages in thread
From: Rajat Jain @ 2007-07-09 11:40 UTC (permalink / raw)
  To: kernelnewbies, linux-newbie

Hi,

Perhaps a little offtopic but no harm in trying ...

Can we always rely on the fact that gcc will pad the following structure?

typedef struct {
    int descrp;      SYSCALL64_STRUCT_ATTR;
    (Automatic padding here?)
    long long pos;   SYSCALL64_STRUCT_ATTR;
    int mode;        SYSCALL64_STRUCT_ATTR;
} lseek64_t;

What is the correct way to make it portable? Explicitly added padding fields?

Thanks,

Rajat
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: Padding in gcc
  2007-07-09 11:40 Padding in gcc Rajat Jain
@ 2007-07-09 14:38 ` pradeep singh
  2007-07-09 14:52   ` Rajat Jain
  2007-07-10 20:15 ` Rodrigo Rubira Branco
  1 sibling, 1 reply; 5+ messages in thread
From: pradeep singh @ 2007-07-09 14:38 UTC (permalink / raw)
  To: Rajat Jain; +Cc: kernelnewbies, linux-newbie

On 7/9/07, Rajat Jain <Rajat.Jain@infogain.com> wrote:
> Hi,
>
> Perhaps a little offtopic but no harm in trying ...
>
> Can we always rely on the fact that gcc will pad the following structure?
>
> typedef struct {
>     int descrp;      SYSCALL64_STRUCT_ATTR;
>     (Automatic padding here?)
>     long long pos;   SYSCALL64_STRUCT_ATTR;
>     int mode;        SYSCALL64_STRUCT_ATTR;
> } lseek64_t;
>
> What is the correct way to make it portable? Explicitly added padding fields?
may be i am missing something but why is this not portable? And how
does padding makes this portable?
Please enlighten me.
Thanks
>
> Thanks,
>
> Rajat
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>


-- 
play the game
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* RE: Padding in gcc
  2007-07-09 14:38 ` pradeep singh
@ 2007-07-09 14:52   ` Rajat Jain
  2007-07-09 15:21     ` pradeep singh
  0 siblings, 1 reply; 5+ messages in thread
From: Rajat Jain @ 2007-07-09 14:52 UTC (permalink / raw)
  To: pradeep singh; +Cc: kernelnewbies, linux-newbie

[-- Attachment #1: Type: text/plain, Size: 992 bytes --]

Hi,
 
>>
>> Can we always rely on the fact that gcc will pad the following structure?
>>
>> typedef struct {
>>     int descrp;      SYSCALL64_STRUCT_ATTR;
>>     (Automatic padding here?)
>>     long long pos;   SYSCALL64_STRUCT_ATTR;
>>     int mode;        SYSCALL64_STRUCT_ATTR;
>> } lseek64_t;
>>
>> What is the correct way to make it portable? Explicitly added padding fields?

>may be i am missing something but why is this not portable? And how
>does padding makes this portable?

Hi ... sorry I could not ask very well, what I wanted to. I have a piece of code that ASSUMES that the above structure is padded (and I do not want to change that code). So how can I make sure that this structure is always padded (Is there any other way apart from adding explicit padding field?) 
 
So like we have a "packed" gcc attribute, do we have a "padded" gcc attribute or something like that (that ensures that gcc will always pad this structure.).
 
Thanks,
Rajat
 
 

[-- Attachment #2: Type: text/html, Size: 2118 bytes --]

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

* Re: Padding in gcc
  2007-07-09 14:52   ` Rajat Jain
@ 2007-07-09 15:21     ` pradeep singh
  0 siblings, 0 replies; 5+ messages in thread
From: pradeep singh @ 2007-07-09 15:21 UTC (permalink / raw)
  To: Rajat Jain; +Cc: kernelnewbies, linux-newbie

On 7/9/07, Rajat Jain <Rajat.Jain@infogain.com> wrote:
>
>
>
> Hi,
>
> >>
> >> Can we always rely on the fact that gcc will pad the following structure?
> >>
> >> typedef struct {
> >>     int descrp;      SYSCALL64_STRUCT_ATTR;
> >>     (Automatic padding here?)
> >>     long long pos;   SYSCALL64_STRUCT_ATTR;
> >>     int mode;        SYSCALL64_STRUCT_ATTR;
> >> } lseek64_t;
> >>
> >> What is the correct way to make it portable? Explicitly added padding
> fields?
>
> >may be i am missing something but why is this not portable? And how
> >does padding makes this portable?
>
> Hi ... sorry I could not ask very well, what I wanted to. I have a piece of
> code that ASSUMES that the above structure is padded (and I do not want to
> change that code). So how can I make sure that this structure is always
> padded (Is there any other way apart from adding explicit padding field?)
>
> So like we have a "packed" gcc attribute, do we have a "padded" gcc
> attribute or something like that (that ensures that gcc will always pad this
> structure.).
GCC will always pad it for best alignment depending on the
architecture. There is attribute to avoid this padding  though.
But padding is done by default depending on architecture for which you
compile your program.
So as long as cross compiliation process is correct, it should work i guess.

OTOH do you want to add just a fixed number of bytes irrespective of
the architecture?

Thanks
[PS : psbl has blacklisted me ,please CC to newbies too, just in case]

>
> Thanks,
> Rajat
>
>


-- 
play the game
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: Padding in gcc
  2007-07-09 11:40 Padding in gcc Rajat Jain
  2007-07-09 14:38 ` pradeep singh
@ 2007-07-10 20:15 ` Rodrigo Rubira Branco
  1 sibling, 0 replies; 5+ messages in thread
From: Rodrigo Rubira Branco @ 2007-07-10 20:15 UTC (permalink / raw)
  To: Rajat Jain; +Cc: kernelnewbies, linux-newbie

[-- Attachment #1: Type: text/plain, Size: 1321 bytes --]

On Mon, 2007-07-09 at 17:10 +0530, Rajat Jain wrote:
> Hi,
> 
> Perhaps a little offtopic but no harm in trying ...
> 
> Can we always rely on the fact that gcc will pad the following structure?
> 
> typedef struct {
>     int descrp;      SYSCALL64_STRUCT_ATTR;
>     (Automatic padding here?)
>     long long pos;   SYSCALL64_STRUCT_ATTR;
>     int mode;        SYSCALL64_STRUCT_ATTR;
> } lseek64_t;
> 
> What is the correct way to make it portable? Explicitly added padding fields?
> 
> Thanks,
> 
> Rajat
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs

Unless you explicitly say this structure is packed
(__attribute__((packed))) gcc will align it... for sure you need to take
care for yourself when you are trying to use different cache lines for
members of this structure.

Anyway, the code itself is portable, since you are just using C.


cya,


rodrigo (BSDaemon).

-- 
Rodrigo Rubira Branco
Software Engineer 
Advanced Linux Response Team (ALRT) / Linux on Power Toolchain
IBM Linux Technology Center (IBM/LTC)
rrbranco@br.ibm.com

GPG KeyID: 1FCEDEA1

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2007-07-10 20:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-09 11:40 Padding in gcc Rajat Jain
2007-07-09 14:38 ` pradeep singh
2007-07-09 14:52   ` Rajat Jain
2007-07-09 15:21     ` pradeep singh
2007-07-10 20:15 ` Rodrigo Rubira Branco

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox