Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Is C ready to become a safer language? Date: Sun, 11 Feb 2024 13:47:12 -0800 Organization: None to speak of Lines: 51 Message-ID: <87o7cmad27.fsf@nosuchdomain.example.com> References: <86eddl5bag.fsf@linuxsc.com> <8734tzdepl.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="a3ea5551d1916ca86f611a52355c117b"; logging-data="1205929"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wOEK7KwXht1hyO0ht6PuZ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:ffneEqoldwYcnj3+7HBLrVRgJHk= sha1:/VtW+Kf7o4VzIAjyJE6IOu7ibGk= Xref: csiph.com comp.lang.c:382350 Thiago Adams writes: > Em 2/10/2024 9:31 PM, Keith Thompson escreveu: >> bart writes: >>> On 10/02/2024 01:59, Tim Rentsch wrote: >>>> bart writes: >>>> [...] >>>> >>>>> This is something which has long been of fascination to me: how >>>>> exactly do you get a C compiler to actually fail a program with a >>>>> hard error when there is obviously something wrong, while not also >>>>> failing on completely harmless matters. >> The only thing that *requires* a compiler to reject a translation >> unit >> is the #error directive. For any violation of a syntax rule or >> constraint, the standard only requires a *diagnostic message*, which can >> be a non-fatal warning. > > I haven't checked the standard but > > #if 1/0 > #endif > > > :4:6: error: division by zero in preprocessor expression > 4 | #if 1/0 > | ~^~ > > > stops compilation. Then I suggest you check the standard. It's perfectly valid for an implementation to choose to stop compilation if it encounters 1/0 in a preprocessor expression, but it's not required. "The resulting tokens compose the controlling constant expression which is evaluated according to the rules of 6.6." 6.6, Constraints: "Each constant expression shall evaluate to a constant that is in the range of representable values for its type." So that's simply a constraint violation, requiring a diagnostic but not requiring the translation unit to be rejected. > With constexpr in C23 I guess division by 0 will stop code generation > as well. No, it merely requires a constant expression. constexpr int n = 1/0; is a constraint violation, requiring a diagnostic but not requiring rejection. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */