Path: ...!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: Wed, 19 Mar 2025 11:56:00 -0700 Organization: None to speak of Lines: 32 Message-ID: <87wmcku9xb.fsf@nosuchdomain.example.com> References: <868qp1ra5f.fsf@linuxsc.com> <864izpr3nk.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 19 Mar 2025 19:56:07 +0100 (CET) Injection-Info: dont-email.me; posting-host="6b2adc3539d30183fea78a893643ef1f"; logging-data="1572559"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mBA1qg/T+Gn/4kZ2zqPzk" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:FyVe2LFg3MFLUm/RPrH0khps3h8= sha1:BdPtrZqV3WJEa3lErZoSQJqQjzs= Bytes: 2477 James Kuyper writes: > On 3/19/25 13:23, DFS wrote: > ... >>     int64_t n = 0, max = 0, thismax = 0; > ... >>     printf("\nmax n = %lld reached at input = %d\n", max, input); > ... >> You'll get compilation warnings about the printf specifier used with >> int64_t. > > Not if you use the correct specifier: > #include > printf("\nmax n = %" PRId64 " reached at input = %d\n", max, input); Or you can use long long and "%lld" (that's what I did). long long is at least 64 bits and is guaranteed to exist (in C99 and later, and the autotester uses "gcc -std=c99"). int64_t is exactly 64 bits and is not guaranteed to exist. (In every C99 or later implementation I'm aware of, long long and int64_t are both exactly 64 bits.) Another alternative for output is to cast to intmax_t and use "%jd". (Why "j"? It was available.) Input with *scanf() is slightly trickier; you can't just cast the pointer argument. (And the *scanf() functions have undefined behavior on numeric input if the input is out of range. fgets() with strto*() is a safer alternative if you can't be sure what the input is going to look like.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */