Angel
6/12/2011 9:27:00 PM
On 2011-06-12, Tech ID <tech@spamtrap.invalid> wrote:
> struct pad1 {
> char c1;
>
> };
>
> struct pad2 {
> char c1;
> int x;
>
> };
>
> struct pad3 {
> char c1;
> char c2;
> int x;
>
> };
>
> struct pad4 {
> char c1;
> char c2;
> int x;
> struct pad1 {
> char c1;
> };
>
> };
>
> What will be the sizeof for the structs above? (for 32-bit and 64-bit
> machines).
As given, the definition of struct pad4 is incorrect, as it redefines
struct pad1. With that corrected, the sizes are as follows on the
systems I tested on:
x86_64, 64-bit Linux:
1, 8, 8, 12
sparc64, 64-bit Linux with 32-bit user land:
1, 8, 8, 12
As others pointed out though, there is no standard for this and the
sizes will likely vary on different hardware and operating systems.
--
"C provides a programmer with more than enough rope to hang himself.
C++ provides a firing squad, blindfold and last cigarette."
- seen in comp.lang.c