home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d07xx / d0766.lha / ISAM / examples / offsetof.c < prev    next >
C/C++ Source or Header  |  1992-11-21  |  971b  |  42 lines

  1. #include <stdio.h>
  2. #include <stddef.h>
  3.  
  4.  
  5. /*  if you don't have stddef.h, use the following:
  6.  
  7.    typedef unsigned int size_t;
  8.  
  9.    #define offsetof(type,memb) (size_t)&(((type *)0L)->memb)
  10.  
  11. */
  12.  
  13. void main ( int argc, char *(argv[]) )
  14. {
  15.  
  16.   struct Employee {
  17.      int EmpNo;
  18.      char Name[31];
  19.      float Salary;
  20.      char SSNo [11]; /* incl. '-' */
  21.   };
  22.  
  23.  
  24.   printf ( "\n\n" );
  25.  
  26.   printf ( "Size of struct Employee: %d bytes.\n\n",
  27.            sizeof (struct Employee ) );
  28.  
  29.   printf ( "The offset of EmpNo  in the Employee struct is %u.\n",
  30.             offsetof( struct Employee, EmpNo ) );
  31.   printf ( "The offset of Name   in the Employee struct is %u.\n",
  32.             offsetof( struct Employee, Name ) );
  33.   printf ( "The offset of Salary in the Employee struct is %u.\n",
  34.             offsetof( struct Employee, Salary ) );
  35.   printf ( "The offset of SSNo   in the Employee struct is %u.\n",
  36.             offsetof( struct Employee, SSNo ) );
  37.  
  38.   printf ( "\n\n" );
  39.  
  40.   return;
  41. }
  42.