Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.std.c Subject: Re: contradiction about the INFINITY macro Date: Fri, 08 Oct 2021 08:30:22 -0700 Organization: A noiseless patient Spider Lines: 38 Message-ID: <86sfxbpm9d.fsf@linuxsc.com> References: <20210930012112$48d9@zira.vinc17.org> <87pmsqizrh.fsf@nosuchdomain.example.com> <20210930105413$d6e8@zira.vinc17.org> <87lf3ehy4v.fsf@nosuchdomain.example.com> <20211001083755$efb3@zira.vinc17.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="00819d90e026a0feda9a088fdad5956f"; logging-data="10339"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ouiiSTRxfoTTb1woTZib1ZZT5K8+oaVo=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:rRAnrm3JHyIpwefveDFH2HRB9Fc= sha1:B+SM0lzVhuCZWbnuM9o+VoeU/0Y= Xref: csiph.com comp.std.c:6339 Vincent Lefevre writes: > In article <87lf3ehy4v.fsf@nosuchdomain.example.com>, > Keith Thompson wrote: [...] >> It means that if a program assumes that INFINITY is meaningful, and >> it's compiled for a target system where it isn't, a diagnostic is >> guaranteed. And again, it might have made more sense to say that >> INFINITY is not defined for such implementations (as is done for >> the NAN macro), but perhaps there was existing practice. > > Yes, currently there is no way of fallback (without things like > autoconf tests). > > Shouldn't the standard by changed to make INFINITY conditionally > defined (if not required to expand to a true infinity)? [...] To me it seems better for INFINITY to be defined as it is rather than being conditionally defined. If what is needed is really an infinite value, just write INFINITY and the code either works or compiling it gives a diagnostic. If what is needed is just a very large value, write HUGE_VAL (or HUGE_VALF or HUGE_VALL, depending) and the code works whether infinite floating-point values are supported or not. If it's important that infinite values be supported but we don't want to risk a compilation failure, use HUGE_VAL combined with an assertion assert( HUGE_VAL == HUGE_VAL/2 ); Alternatively, use INFINITY only in one small .c file, and give other sources a make dependency for a successful compilation (with of course a -pedantic-errors option) of that .c file. I don't see that having INFINITY be conditionally defined buys anything, except to more or less force use of #if/#else/#endif blocks in the preprocessor. I don't mind using the preprocessor when there is a good reason to do so, but here I don't see one.