× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Joep Beckeringh wrote:
According to Kernighan and Ritchie the implementation-defined limits of a C compiler are contained within the limits.h header file. Short and int should be 2 bytes minimum; long should be 4 bytes minimum.


At one time, the relative sizes of int, short, and long were defined by the relationship "sizeof(short) <= sizeof(int) <= sizeof(long)", where "sizeof(int)" was normally the preferred word size of the CPU in bytes. So it was possible that in certain implementations of the C compiler, all three types would map to the same size.


These days, I believe the current C standard is a bit more specific:

sizeof(char)      >= 1 (bytes)
sizeof(short)     >= 2
sizeof(int)       >= 2
sizeof(long)      >= 4
sizeof(long long) >= 8

which is a bit more useful from the point of view of software portability.

In practice, it's not that big a deal, and I've never seen a problem with mismatched integer sizes in all my years of C programming. Unless you know you need to store potentially very large integer or unsigned values, or you need to match some external interface, just declaring your numeric variables as int is normally good enough.

Cheers! Hans


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.