#include /****************************************************************** * Try to determine the structure of the machine it is run on. * * Copyright Yves Dorfsman, December 1999 ******************************************************************/ main (void) { unsigned int i, j, anint = 1, base = 1, sint, schar; /* unsigned long long base = 256; */ char *pt; sint = sizeof(int); schar = sizeof(char); pt = (char *) &anint; if (schar > 1) { fprintf(stderr, "This program was written assuming size of char to be 1 byte\n"); return 1; } for (i = 0 ; i < sint ; i++) { j = (i > 0) ? i + 1 : 0; anint = anint + base * j; base = base * 256; } printf("\nSize of an char: %i byte\n", sizeof(char)); printf("Size of an int: %i bytes\n", sizeof(int)); printf("Size of an long int: %i bytes\n", sizeof(long int)); printf("Size of an long long int: %i bytes\n", sizeof(long long int)); printf("Size of an float: %i bytes\n", sizeof(float)); printf("Size of an double: %i bytes\n", sizeof(double)); printf("Size of an long double: %i bytes\n", sizeof(long double)); if (*pt == 1) printf("\nYour machine uses a little endian architecture.\n"); else if (*(pt+sint-1) == 1) printf("\nYour machine uses a big endian architecture.\n"); else printf("\nI am not entirely sure what architecture your machine is using.\n"); printf("\nIn memory, the number 0x%x is represented as the four bytes:\n", anint); for (i = 0 ; i < sint ; i++) printf("%.2x ", *(pt+i)); printf("\n\n"); }