5 karma · joined Nov 29, 2016 (10y ago) · 2 submissions
comment 9y ago · link · parent
comment 10y ago · link · parent
int main() {
assert(sizeof(signed char) == 1);
assert(sizeof(short) == 2);
assert(sizeof(int) == 4);
assert(sizeof(long long) == 8);
return 0;
}
I'm not interested in the language lawyering, because yes I know the standard provides more freedom to compilers. I just think those definitions are very universal for any real computer that would otherwise run my software. Please don't bring up Windows 3.1, that's about as relevant to most of us a PDP-11.And for what it's worth, using typedefs based on the above provides more readable printf strings. This is hideous:
int main() {
int64_t portable = 123;
printf("Ugly: %" PRId64 "\n", portable);
return 0;
}
Where this is acceptable: int main() {
long long palatable = 123;
printf("Better: %lld\n", palatable);
return 0;
}