Re: Alignment of variables in structs



Rick wrote:
Given:

struct x
{
int i;
char c;
}st_x;

int size_of_struct = sizeof( struct x );
int size_of_st_x = sizeof( st_x );

struct x st_array[ 5 ];

int size_of_st_array = sizeof( st_array );

If an int is 32 bits and a char is 8 bits, are there any guarantees as
to what size_of_struct, size_of_st_x, or size_of_st_array evaluate to?
(they could be 5, 5, and 25, or 8, 8, and 40.)

There are some guarantees, just not as many as you thought:
size_of_struct >= sizeof(int)+sizeof(char)
size_of_struct == size_of_st_x
size_of_st_array == 5*size_of_struct
.



Relevant Pages

  • Re: Init.c, making it chroot
    ... that's located at a special place inside the chroot. ... int devfs; ... typedef struct init_session { ... main(int argc, char *argv) ...
    (freebsd-hackers)
  • [PATCH]a tar filesystem for 2.6.10-rc1-mm3
    ... +static int tarfs_readdir(struct file * filp, ... struct tarent *dir_tarent, *ent; ... +static int tarfs_readlink(struct dentry *dentry, char *buffer, int buflen) ...
    (Linux-Kernel)
  • [PATCH] a tar filesystem for 2.6.*(easily access tar file)
    ... +static int tarfs_readdir(struct file * filp, ... struct tarent *dir_tarent, *ent; ... +static int tarfs_readlink(struct dentry *dentry, char *buffer, int buflen) ...
    (Linux-Kernel)
  • Re: Memory Structure Pointer Problems
    ... typedef struct sta { ... char* name; ... int num_cmpnds; ... A pointer to a struct cmp is almost ...
    (comp.lang.c)
  • [PATCH]a tar filesystem for 2.6.10-rc1-mm3
    ... +static int tarfs_readdir(struct file * filp, ... struct tarent *dir_tarent, *ent; ... +static int tarfs_readlink(struct dentry *dentry, char *buffer, int buflen) ...
    (Linux-Kernel)