Sujet : Re: Suggested method for returning a string from a C program?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 20. Mar 2025, 20:07:07
Autres entêtes
Organisation : None to speak of
Message-ID : <878qozttb8.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Gnus/5.13 (Gnus v5.13)
bart <
bc@freeuk.com> writes:
On 20/03/2025 12:09, Tim Rentsch wrote:
Michael S <already5chosen@yahoo.com> writes:
>
I suspected that, but was not sure, so suggested to DFS a type that I am
sure about.
The width of char and [un]signed char must be at least 8 bits.
The width of [un]signed short must be at least 16 bits.
The width of [un]signed int must be at least 16 bits.
The width of [un]signed long must be at least 32 bits.
The width of [un]signed long long must be at least 64 bits.
That should be easy enough to remember now.
>
That table suggests that any program mixing 'short' and 'int' is
suspect. If 'int' doesn't need to store values beyond 16 bits, then
why not use 'short'?
POSIX requires int to be at least 32 bits wide. I believe Win32
requires int to be exactly 32 bits wide. If you're writing code that
already depends on either POSIX or Win32, it's reasonable to rely on
that assumption.
[...]
My suggestion for writing code that is not going to run on 16-bit or
lesser (or unusual) hardware is to assume:
>
char 8 bits
short 16 bits
int 32 bits
long long 64 bits
>
and to forget 'long'.
Are those widths supposed to be exact? You can assume those types are
*at least* that wide (if you're already relying on POSIX or Win32), but
I wouldn't assume the widths are exact unless the code was *only* ever
intended to be used with a specific model. (I've used POSIX-based
systems with 64-bit short, for example.)
If I want exact-width types, I know where to find them.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */