Deutsch English Français Italiano |
<86jz8kpzam.fsf@linuxsc.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch <tr.17687@z991.linuxsc.com> Newsgroups: comp.lang.c Subject: Re: Suggested method for returning a string from a C program? Date: Wed, 19 Mar 2025 12:59:13 -0700 Organization: A noiseless patient Spider Lines: 32 Message-ID: <86jz8kpzam.fsf@linuxsc.com> References: <vrd77d$3nvtf$2@dont-email.me> <868qp1ra5f.fsf@linuxsc.com> <vrdhok$47cb$2@dont-email.me> <20250319115550.0000676f@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Wed, 19 Mar 2025 20:59:13 +0100 (CET) Injection-Info: dont-email.me; posting-host="f38801bdea7b04066d3e2a5989bc7bcf"; logging-data="1616995"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18uQPtcpuBJUiGanFctFXlMndcTlOVqsbw=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:huexaqcsbG57V+WjjUXdv1iQruw= sha1:YCkxrbxc+nPW2aWQIb75m55QxW4= Bytes: 2222 Michael S <already5chosen@yahoo.com> writes: > 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. The number 18997161173 is odd. The largest value reached is three times that, plus 1, which is 56991483520. > Something like int64_t would be safer. Using unsigned long long is safer still, and easier, because there is no need for hoop-jumping to print them out with printx.