Re: Suggested method for returning a string from a C program?

Liste des GroupesRevenir à cl c 
Sujet : Re: Suggested method for returning a string from a C program?
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.c
Date : 20. Mar 2025, 13:09:21
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86r02roqdq.fsf@linuxsc.com>
References : 1 2 3 4 5 6 7
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Michael S <already5chosen@yahoo.com> writes:

On Wed, 19 Mar 2025 17:38:12 +0000
Richard Heathfield <rjh@cpax.org.uk> wrote:
>
On 19/03/2025 17:23, DFS wrote:
>
On 3/19/2025 5:55 AM, Michael S wrote:
>
On Wed, 19 Mar 2025 00:38:44 -0400
DFS <nospam@dfs.com> wrote:
>
On 3/18/2025 11:07 PM, Tim Rentsch wrote:
>
>
Have you thought about how large the value of 'n' can
become inside the while() loop?
>
I was too smug in my first reply.  After Keith pointed out I
needed
to read from stdin, I submitted the code again and it passed some
tests but failed with 'OUTPUT LIMIT EXCEEDED' when n = 159487.
>
Updating int to long worked, and now I'm bona fide!
>
So thanks.
>
What you did happens to be sufficient for a particular environment
(supposedly, x86-64 Linux) used both by yourself and by the
server that
tests results.
In more general case, 'long' is not guaranteed to handle
numbers in
range up to 18,997,161,173 that can happen in this test.
>
How did you determine that?
>
By the language definition.
>
Well, not exactly.
I never read C Standard docs except the very first one that I read
more that I read more than 33 years ago, so not very likely to
remember it literally.
Let's say that I know this particular bit of trivia from 1st hand
experience and from reading few ABI definitions.
>
++++++++++++++++++++++++++++++++++++++++++++++
>
5.2.4.2.1 Sizes of integer types <limits.h>
>
[...]
>
? minimum value for an object of type long int
LONG_MIN
-2147483647 // ?(231 ? 1)
>
? maximum value for an object of type long int
LONG_MAX
+2147483647 // 231 ? 1
>
++++++++++++++++++++++++++++++++++++++++++++++
>
That is, the long int type is required to have a sign bit and at
least 31 value bits, giving a guaranteed minimum range of
-2147483647 to 2147483647.  That's 2 thou mill.
>
You can squeeze another bit out of it by going unsigned: 0 to
4294967295.  That's 4 thou mill.
>
 From C99 onwards you can use long long int to give you 63 (or 64
for unsigned) value bits - printf with %lld or %llu.  Roughly 9
mill mill mill and 18 mill mill mill respectively.
>
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.

Date Sujet#  Auteur
24 Feb 26 o 

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal