Padding in gcc

Padding in gcc

am 09.07.2007 13:40:51 von Rajat Jain

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

Re: Padding in gcc

am 09.07.2007 16:38:35 von pradeep singh

On 7/9/07, 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?
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

RE: Padding in gcc

am 09.07.2007 16:52:47 von Rajat Jain

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,
=20
>>
>> 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?)=20
=20
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.).
=20
Thanks,
Rajat
=20
=20

------_=_NextPart_001_01C7C239.7EBBDA5D
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

charset=3Diso-8859-1">=0A=
=0A=
=0A=
=0A=
=0A=
6.5.7652.24">=0A=
Re: Padding in gcc=0A=
=0A=
=0A=

=0A=
size=3D2>Hi,
=0A=
 
=0A=
>>
>> Can we always rely on =
the fact =0A=
that gcc will pad the following structure?
>>
>> =
typedef =0A=
struct {
>>     int =0A=
descrp;      =0A=
SYSCALL64_STRUCT_ATTR;
>>     (Automatic =
padding =0A=
here?)
>>     long long pos;   =0A=
SYSCALL64_STRUCT_ATTR;
>>     int =0A=
mode;        =0A=
SYSCALL64_STRUCT_ATTR;
>> } lseek64_t;
>>
>> =
What is =0A=
the correct way to make it portable? Explicitly added padding =0A=
fields?
=0A=
>may be i am missing something but why =
is this not =0A=
portable? And how
>does padding makes this =
portable?
=0A=
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?)
=0A=
 
=0A=
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.).
=0A=
 
=0A=
Thanks,
=0A=
Rajat
=0A=
 
=0A=
 
=0A=
=0A=
=0A=

------_=_NextPart_001_01C7C239.7EBBDA5D--

--
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

Re: Padding in gcc

am 09.07.2007 17:21:12 von pradeep singh

On 7/9/07, Rajat Jain 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

Re: Padding in gcc

am 10.07.2007 22:15:28 von Rodrigo Rubira Branco

--=-5jW3SeMAT/Q5Q3O44MPf
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Mon, 2007-07-09 at 17:10 +0530, Rajat Jain wrote:
> Hi,
>=20
> Perhaps a little offtopic but no harm in trying ...
>=20
> Can we always rely on the fact that gcc will pad the following structure?
>=20
> typedef struct {
> int descrp; SYSCALL64_STRUCT_ATTR;
> (Automatic padding here?)
> long long pos; SYSCALL64_STRUCT_ATTR;
> int mode; SYSCALL64_STRUCT_ATTR;
> } lseek64_t;
>=20
> What is the correct way to make it portable? Explicitly added padding fie=
lds?
>=20
> Thanks,
>=20
> Rajat
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" i=
n
> 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).

--=20
Rodrigo Rubira Branco
Software Engineer=20
Advanced Linux Response Team (ALRT) / Linux on Power Toolchain
IBM Linux Technology Center (IBM/LTC)
rrbranco@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@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