Hacker News new | past | comments | ask | show | jobs | submit login

Don't. Every type has its place in a well-defined structure, passing through main architecture changes. Use 'int' if the expected range of values fit in 16 bits, use 'long' if it fits in 32 bits and use 'long long' otherwise. 'int' is guaranteed to be the fastest at-least-16 bit type and 'long' is guaranteed to be the fastest at-least-32 bit type for any architecture (matching the register width on most 32/64 bit platforms - except Windows, and being 32-bit wide even on 8/16 bit architectures), and each of these types have their own promotion class.

Don't use fixed width types by default as printing them or converting to string correctly will get ugly: printf("... %" PRId32 " ...");

Generally avoid the use of fixed-width 8-bit or 16-bit types in calculations or you might shoot yourself in the foot due to integer promotion rules.

Use fixed width types only for things that pass the boundary of a system, like in HW registers, serializing, database storage or network packets, but cast only at the end when converting to the type (optionally followed by bitwise manipulations) and cast immediately to other type when processing (after bitfield extraction and such things, of course).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: