home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
database
/
isam
/
examples
/
offsetof.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-27
|
971b
|
42 lines
#include <stdio.h>
#include <stddef.h>
/* if you don't have stddef.h, use the following:
typedef unsigned int size_t;
#define offsetof(type,memb) (size_t)&(((type *)0L)->memb)
*/
void main ( int argc, char *(argv[]) )
{
struct Employee {
int EmpNo;
char Name[31];
float Salary;
char SSNo [11]; /* incl. '-' */
};
printf ( "\n\n" );
printf ( "Size of struct Employee: %d bytes.\n\n",
sizeof (struct Employee ) );
printf ( "The offset of EmpNo in the Employee struct is %u.\n",
offsetof( struct Employee, EmpNo ) );
printf ( "The offset of Name in the Employee struct is %u.\n",
offsetof( struct Employee, Name ) );
printf ( "The offset of Salary in the Employee struct is %u.\n",
offsetof( struct Employee, Salary ) );
printf ( "The offset of SSNo in the Employee struct is %u.\n",
offsetof( struct Employee, SSNo ) );
printf ( "\n\n" );
return;
}