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 00:02:31 -0700 Organization: A noiseless patient Spider Lines: 49 Message-ID: <86wnmoov7c.fsf@linuxsc.com> References: <20210930012112$48d9@zira.vinc17.org> <87pmsqizrh.fsf@nosuchdomain.example.com> <20210930105413$d6e8@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="29989"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Cd6Wy1iQX7V7TumVUY0FxRjfw2+yX/ZY=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:1ozefBDM6+54n19AKdFQ8Rfklug= sha1:iXunyyE5Hflx3yk0ztVUDzatZtI= Xref: csiph.com comp.std.c:6337 Vincent Lefevre writes: > In article <87pmsqizrh.fsf@nosuchdomain.example.com>, > Keith Thompson wrote: [.. use of the INFINITY macro in an implementation that does not have a float value for infinity..] >> If I understand correctly, it means that if an infinite value is >> not available, then a program that refers to the INFINITY macro (in >> a context where it's treated as a floating-point expression) >> violates that constraint, resulting in a required diagnostic. > > I think the consequence is more than a diagnostic (which may yield > a compilation failure in practice, BTW): AFAIK, the standard does > not give a particular definition for "overflows at translation > time", which would make it undefined behavior as usual for > overflows. The compound phrase does not need defining because its relevant constituent elements are defined in the C standard. The word "overflows" is defined for floating point types in 7.12.1 paragraph 5 A floating result overflows if the magnitude of the mathematical result is finite but so large that the mathematical result cannot be represented without extraordinary roundoff error in an object of the specified type. [...] The word "translation" is defined in detail in section 5.1.1. The compound phrase "overflows at translation time" is simply a combination of these defined terms under normal rules of English usage. Moreover, the C standard is quite clear that violating a constraint must evoke a diagnostic even if there is also undefined behavior. Section 5.1.1.3 paragraph 1 says this: A conforming implementation shall produce at least one diagnostic message (identified in an implementation-defined manner) if a preprocessing translation unit or translation unit contains a violation of any syntax rule or constraint, even if the behavior is also explicitly specified as undefined or implementation-defined. [...] What occurs is defined behavior and (for implementations that do not have the needed value for infinity) violates a constraint. A diagnostic must be produced.