Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: micro-architectural details Date: Wed, 07 Dec 2016 15:28:11 -0800 Organization: None to speak of Lines: 44 Message-ID: References: <8f359715-238c-42b4-b53f-5c5511725fdb@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="8f45946c30f4b59560518fab20622d5e"; logging-data="862"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18sjFy3+Gv800haXuvdliSz" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:0VVW5FqZ+z20yRWoAvXk33qw8ik= sha1:8Sdag+dEfRScVxLUuA+cZkTqUNY= Xref: csiph.com comp.lang.c:98323 BartC writes: > On 07/12/2016 22:44, jacobnavia wrote: > > [Overflow detection] > >> Yes. And not care about whether the results are correct. Just that they >> are calculated very fast. > > Suppose there is a language feature to detect whether an expression has > overflowed that shouldn't have done. > > What can the code then do about it? It can handle the error, just as it would handle any other error. It can give up on some operation and go on to do something else, perhaps after informing the user if appropriate. Here's an example in Ada, a language that supports exceptions and requires an exception to be raised on numeric overflow. It prints "Overflow". Ada does the same thing for array bound errors. with Ada.Text_IO; use Ada.Text_IO; procedure Overflow is N: Integer := Integer'Last; begin N := N + 1; Put_Line("OK"); exception when Constraint_Error => Put_Line("Overflow"); end Overflow; > I can see this being of use when debugging programs, like putting in > array bounds checking, but then it be taken care of with special > checking code put in by the compiler. It doesn't need new language features. It's very difficult to do reliable overflow checking in C without either adding new language features or using extensions. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"