Padding in gcc
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 [at] 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
Re: Padding in gcc
On 7/9/07, Rajat Jain <Rajat.Jain [at] 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 [at] 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 [at] 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
Re: Padding in gcc
On 7/9/07, Rajat Jain <Rajat.Jain [at] 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 [at] 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
RE: Padding in gcc
This is a multi-part message in MIME format.
------_=_NextPart_001_01C7C239.7EBBDA5D
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
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
------_=_NextPart_001_01C7C239.7EBBDA5D
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">=0A=
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">=0A=
<HTML>=0A=
<HEAD>=0A=
=0A=
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.5.7652.24">=0A=
<TITLE>Re: Padding in gcc</TITLE>=0A=
</HEAD>=0A=
<BODY>=0A=
<DIV id=3DidOWAReplyText25958 dir=3Dltr>=0A=
<DIV dir=3Dltr><FONT face=3DArial color=3D#000000 =
size=3D2></FONT>Hi,</DIV>=0A=
<DIV dir=3Dltr> </DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2>>><BR>>> Can we always rely on =
the fact =0A=
that gcc will pad the following structure?<BR>>><BR>>> =
typedef =0A=
struct {<BR>>> int =0A=
descrp; =0A=
SYSCALL64_STRUCT_ATTR;<BR>>> (Automatic =
padding =0A=
here?)<BR>>> long long pos; =0A=
SYSCALL64_STRUCT_ATTR;<BR>>> int =0A=
mode; =0A=
SYSCALL64_STRUCT_ATTR;<BR>>> } lseek64_t;<BR>>><BR>>> =
What is =0A=
the correct way to make it portable? Explicitly added padding =0A=
fields?<BR></FONT></DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2>>may be i am missing something but why =
is this not =0A=
portable? And how<BR>>does padding makes this =
portable?<BR></FONT></DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2>Hi ... sorry I could not ask very well, =
what I wanted =0A=
to. I have a piece of code that ASSUMES that the above structure is =
padded =0A=
(and I do not want to change that code). So how can I =
make sure =0A=
that this structure is always padded (Is there any other way apart from =
adding =0A=
explicit padding field?) </FONT></DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2></FONT> </DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2>So like we have a "packed" gcc attribute, =
do we have a =0A=
"padded" gcc attribute or something like that (that ensures that gcc =
will always =0A=
pad this structure.).</FONT></DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2></FONT> </DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2>Thanks,</FONT></DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2>Rajat</FONT></DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2></FONT> </DIV>=0A=
<DIV dir=3Dltr><FONT size=3D2> </DIV></FONT></DIV>=0A=
=0A=
</BODY>=0A=
</HTML>
------_=_NextPart_001_01C7C239.7EBBDA5D--
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis [at] nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Padding in gcc
--=-5jW3SeMAT/Q5Q3O44MPf
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
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 fie=
lds?
>
> Thanks,
>
> Rajat
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" i=
n
> the body of a message to majordomo [at] 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 [at] br.ibm.com
GPG KeyID: 1FCEDEA1
--=-5jW3SeMAT/Q5Q3O44MPf
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
iD8DBQBGk+jgRpuC3B/O3qERAqFWAJ95Zu0SY8g6CDhDEW7p6U1487l2sACg gl1K
3pJ5Z50VFz2C7Z/Q2Hsp5uU=
=lgPZ
-----END PGP SIGNATURE-----
--=-5jW3SeMAT/Q5Q3O44MPf--
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo [at] 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