sizeof struct

Alan Hobesh afh at PacBell.COM
Wed Sep 6 08:27:37 AEST 1989



The following c code prints the size of the definded structure to be 44,
when compiled on an AT&T 3B20 running UNIX V5.2.1.

/*------------------------------------------------------------*/
#include <stdio.h>
struct REC
{
  char   	vis_date[6];
  char   	vis_time[6]; 
  char   	vis_port[2];
  char   	vis_rec_type[2];
  char      	vis_seq_num[5];
  char         	vis_phone_num[10];
  char         	vis_switch[4];
  char         	vis_stop_dur[6];
  char          vis_cr;
} recbuf;

main()
{

        printf("struct = %d\n",sizeof(struct REC));

}
/*------------------------------------------------------------*/

However, when the code is downloaded to a PC and compiled using Turbo C,
the size of the structure is reported to be 42.

Why is there a difference and which is the correct size?



More information about the Comp.lang.c mailing list