Sujet : Re: integer divided by zero
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 28. Apr 2025, 21:44:03
Autres entêtes
Organisation : None to speak of
Message-ID : <871ptc10fg.fsf@nosuchdomain.example.com>
References : 1 2
User-Agent : Gnus/5.13 (Gnus v5.13)
Richard Heathfield <
rjh@cpax.org.uk> writes:
On 25/04/2025 18: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.
>
C? I doubt it very much.
I showed an example earlier in this thread.
A simpler example:
$ uname -ms
Linux aarch64
$ cat c.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc != 3) exit(EXIT_FAILURE);
const int a = atoi(argv[1]);
const int b = atoi(argv[2]);
printf("%d / %d = %d\n", a, b, a/b);
}
$ ./c 100 7
100 / 7 = 14
$ ./c 1 0
1 / 0 = 0
$ ./c 0 0
0 / 0 = 0
$
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */