Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: bart again (UCX64) Date: Mon, 04 Sep 2023 18:15:47 -0700 Organization: A noiseless patient Spider Lines: 36 Message-ID: <86jzt5pgho.fsf@linuxsc.com> References: <20230901104426.371@kylheku.com> <20230901114625.198@kylheku.com> <20230901135123.702@kylheku.com> <878r9p7b13.fsf@nosuchdomain.example.com> <20230901175635.91@kylheku.com> <87h6o95znv.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: dont-email.me; posting-host="6793c8bc2747e0ba6d3890411794594c"; logging-data="1779524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YYvbLADHHHXAMpcexf51kAtx8t8vSFMs=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:RyM4lwI+Oisw6+P3TfjzkWCLBzo= sha1:scN8K7UF8Ju6q3C49DvLtolthzc= Xref: csiph.com comp.lang.c:173931 Keith Thompson writes: > David Brown writes: > >> On 04/09/2023 12:06, Bart wrote: > > [...] > >>> char* fred(void) { >>> (long long int)rand()*3.14159; >>> } >>> int main(void) { >>> printf("%s\n", fred()); >>> } > > [...] > >> As you know, it is not valid C code. As you know, proper C compilers >> will - at least - warn you about it when asked to treat the input >> according to the C standards. As you know, there isn't a compiler in >> the world for any language which will stop programmers from writing >> incorrect code. > > Given the context of the discussion, pedantry seems appropriate. > > It's invalid C code because it doesn't declare rand() and printf(), > correctable by adding `#include ` and `#include `. > (It also contains NO-BREAK SPACE characters, but that's that's just a > Usenet formatting issue.) > > Other than that, a conforming C compiler is not required to diagnose > the above code. It does have undefined behavior, and a C compiler is > likely to warn about it with appropriate warnings, but it does not > violate any syntax rule or constraint. I say it does.