(no title)
dianeb | 7 years ago
Most code really doesn't need this much detail -- "sizeof" is your friend -- You can start with something like this:
sizes.c
#include <stdio.h>
int isBigEndian() {
int x = 1;
return(*(char *)&x != 1);
}
int main() {
printf("This is a %s endian machine\n", isBigEndian() ? "big" : "little");
printf("char: %lu\n", sizeof(char));
printf("short: %lu\n", sizeof(short));
printf("int: %lu\n", sizeof(int));
printf("long: %lu\n", sizeof(long));
printf("long long: %lu\n", sizeof(long long));
printf("float: %lu\n", sizeof(float));
printf("double: %lu\n", sizeof(double));
printf("long double: %lu\n", sizeof(long double));
}
compile as: cc -std=c17 sizes.c...and add whatever else you need as you go along. A version of my compiler information code is in my forthcoming book.
kqr2|7 years ago