padding/alignment question.

Eleonora Autore (ely@ns1.avnet.co.uk)
Sat, 30 Oct 1999 19:19:34 +0100 (BST)


Hi guys,

In some structures I noticed a strange thing:

struct ext2_group_desc
{
__u32 bg_block_bitmap; /* Blocks bitmap block */
__u32 bg_inode_bitmap; /* Inodes bitmap block */
__u32 bg_inode_table; /* Inodes table block */
__u16 bg_free_blocks_count; /* Free blocks count */
__u16 bg_free_inodes_count; /* Free inodes count */
__u16 bg_used_dirs_count; /* Directories count */
__u16 bg_pad;
__u32 bg_reserved[3];
};

why are the last 14 bytes split into __u16 and __u32[3]? Isn't it more
economical to write:

struct ext2_group_desc2
{
__u32 bg_block_bitmap; /* Blocks bitmap block */
__u32 bg_inode_bitmap; /* Inodes bitmap block */
__u32 bg_inode_table; /* Inodes table block */
__u16 bg_free_blocks_count; /* Free blocks count */
__u16 bg_free_inodes_count; /* Free inodes count */
__u16 bg_used_dirs_count; /* Directories count */
__u8 bg_reserved[14];
};

a trivial program that prints sizeof of both confirms that it is 32 bytes
in both cases. So, why is it not done via __u8[14]? Is there some
alignment-related issue on non-intel architecture or what?

I saw the same thing in ext2_super_block btw.

Regards,
Tigran.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/