Deutsch   English   Français   Italiano  
<vugi1f$ghms$1@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: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: integer divided by zero
Date: Fri, 25 Apr 2025 19:50:39 +0200
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <vugi1f$ghms$1@dont-email.me>
References: <vughb7$g6cm$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Apr 2025 19:50:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0ae31ad591125cc8dc4c6b4a2207485c";
	logging-data="542428"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18vOIDyjIvtchdO154AUnZeBJND4RY3Xw8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
 Thunderbird/102.11.0
Cancel-Lock: sha1:cLVHy15+XuYGVo768gZbLdTqQEE=
Content-Language: en-GB
In-Reply-To: <vughb7$g6cm$1@dont-email.me>
Bytes: 2359

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.  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.