Deutsch   English   Français   Italiano  
<vreuj1$1asii$4@dont-email.me>

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: DFS <nospam@dfs.com>
Newsgroups: comp.lang.c
Subject: Re: Suggested method for returning a string from a C program?
Date: Wed, 19 Mar 2025 13:23:47 -0400
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <vreuj1$1asii$4@dont-email.me>
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=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 19 Mar 2025 18:23:46 +0100 (CET)
Injection-Info: dont-email.me; posting-host="901d9964429cda711e0950a8728255b7";
	logging-data="1405522"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX197tj0X3b8C0gFsPyQQT7F8"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:sutPgTTH1tWg+N13mnX5I88amjo=
In-Reply-To: <20250319115550.0000676f@yahoo.com>
Content-Language: en-US
Bytes: 2479

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?

I ran the program for inputs 1 to 10^6 (1 million):

Windows11, Tiny C compiler
$ ptime weird 1 1000000
max n = 56991483520 reached at input = 704511
Execution time: 0.559 s

Kali Linux (Windows WSL), gcc
$ time ./weird 1 1000000
max n = 56991483520 reached at input = 704511
real    0m0.330s

(56,991,483,520)



> Something like int64_t would be safer.

Indeed.  My code bombed using long when the input n = 151177.

Used int64_t and it didn't bomb.


Thanks