Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Suggested method for returning a string from a C program? Date: Thu, 20 Mar 2025 12:07:07 -0700 Organization: None to speak of Lines: 45 Message-ID: <878qozttb8.fsf@nosuchdomain.example.com> References: <868qp1ra5f.fsf@linuxsc.com> <20250319115550.0000676f@yahoo.com> <20250319201903.00005452@yahoo.com> <86r02roqdq.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Thu, 20 Mar 2025 20:07:08 +0100 (CET) Injection-Info: dont-email.me; posting-host="2f20008cbcfa55ae60494be276e0bfaa"; logging-data="4043012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gtap0Fv4Pq7pMkgUWSmcy" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:kjeFxFAgj3VEAj3KiwIufFM+bqw= sha1:B3alSuAGRBoTIdWwLfMuXaet3To= Xref: csiph.com comp.lang.c:391432 bart writes: > On 20/03/2025 12:09, Tim Rentsch wrote: >> Michael S 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.com void Void(void) { Void(); } /* The recursive call of the void */