Deutsch English Français Italiano |
<vugo99$m2n2$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Thiago Adams <thiago.adams@gmail.com> Newsgroups: comp.lang.c Subject: Re: integer divided by zero Date: Fri, 25 Apr 2025 16:37:13 -0300 Organization: A noiseless patient Spider Lines: 38 Message-ID: <vugo99$m2n2$2@dont-email.me> References: <vughb7$g6cm$1@dont-email.me> <vugi1f$ghms$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 25 Apr 2025 21:37:14 +0200 (CEST) Injection-Info: dont-email.me; posting-host="798e28d3c2d66a0e3e88ddd606249bea"; logging-data="723682"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+L+V/exV6eggne42wBKD3b2pEcqdmcYLI=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:TIhOAxKTwPxR+2fWx2IVv9e4jeA= Content-Language: en-GB In-Reply-To: <vugi1f$ghms$1@dont-email.me> Bytes: 2603 Em 4/25/2025 2:50 PM, David Brown escreveu: > On 25/04/2025 19:38, Thiago Adams wrote: >> Does anyone know of any platform where integer division by zero >> returns a number, or in other words, where it's not treated as an >> error? I'm asking because division by zero is undefined behaviour, but >> I think division by a constant zero should be a constraint instead. >> > > Some processors might give a specific value for their integer division > instructions for divide by 0 - or they might support masking of relevant > traps, exceptions or other fault mechanisms. Software should probably > not rely on division by 0 behaviour, even if it is in non-portable code. > > But most processors that are too small to have a fault, trap or > exception system are also too small to have division instructions. There > are exceptions, of course. > > Division by a constant 0 is not a constraint in C because that would > require compilers to detect division by zero. This is easy for constant. But conforming compilers > are free to detect it anyway, and issue a warning. Note that compilers > should probably not consider it a fatal error in the code (i.e., one > that stops the compilation) unless the compiler can be sure that the > code in question is not executed. There is no problem having undefined > behaviour in the code until you try to execute that code path. > Since 1/0 is not a constant, then if 1/0 were a constrain, the programmer could use a variable instead. static int zero = 0; 1/zero //ok