Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (1 / 5) |
Uptime: | 45:10:13 |
Calls: | 422 |
Calls today: | 1 |
Files: | 1,024 |
Messages: | 90,304 |
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.
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.
Thiago Adams <thiago.adams@gmail.com> writes:
Em 4/25/2025 4:05 PM, Keith Thompson escreveu:
Thiago Adams <thiago.adams@gmail.com> writes:
Does anyone know of any platform where integer division by zeroDivision by a constant zero is a constraint violation in a context
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.
that requires a constant expression.
Consider this sample
int main(){
int a[1/0];
}
1/0 does not have a value in compile time,
So I believe compilers are making "a" a VLA because 1/0 is
not constant.
1/0 is not a constant expression.
A conforming compiler that supports VLAs (C99, or optionally C11 or
later) would make `a` a VLA, with undefined behavior at runtime when
1/0 is evaluated. For a conforming compiler that doesn't support
VLAs (C89/C90, or optionally C11 or later) the declaration is a
constraint violation.
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.
Em 4/25/2025 5:32 PM, Keith Thompson escreveu:
Thiago Adams <thiago.adams@gmail.com> writes:
[...]
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
They could, but why? `1/zero` is not "ok"; it's undefined behavior.
It could me used in the sample given by Waldek
int signal_error(void) {
return 1/0;
}
int signal_error(void) {
int zero = 0;
return 1/zero;
}
int signal_error(void) {
int zero = 0;
return 1/zero;
}
Wouldn't it be easier just to use raise(3)?
The platform with the most comfortable handling of division
by zeroes is Windows. Win32 allows to catch that errors
easily, whereas with Posix it's hard to continue the code in
the same function or with a calling function.
Am 28.04.2025 um 09:54 schrieb Richard Heathfield:
Tell it to the marines, because the sailors won't believe you.
<https://web.archive.org/web/20221230163646/https://
www.wired.com/1998/07/sunk-by-windows-nt/>
Then they didn't catch the divide by zero.
Am 25.04.2025 um 19:38 schrieb Thiago Adams:
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.
I guess the trap is induced on all platforms since there's no binary representation for +/-inf with integrals.
The platform with the most comfortable handling of division by zeroes
is Windows. Win32 allows to catch that errors easily, whereas with
Posix it's hard to continue the code in the same function or with
a calling function.
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.
On 4/27/25 9:33 AM, Bonita Montero wrote:
Am 25.04.2025 um 19:38 schrieb Thiago Adams:
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.
I guess the trap is induced on all platforms since there's no binary
representation for +/-inf with integrals.
The platform with the most comfortable handling of division by zeroes
is Windows. Win32 allows to catch that errors easily, whereas with
Posix it's hard to continue the code in the same function or with
a calling function.
NO, not all processors have a trap for divide by zero on integers, and
many that do allow the disabling of that trap.
The results of the divide are just declaired to be undefined (but their
is likely some definite result that will happen due to the division
algorithm being performed).
Bonita Montero <Bonita.Montero@gmail.com> writes:
Am 28.04.2025 um 13:15 schrieb Richard Damon:
NO, not all processors have a trap for divide by zero on integers,
and many that do allow the disabling of that trap.
Windows requires processors that can trap divisions by zero,
No, Windows only runs on processors (x86) that happen to trap
divisions by zero. Linux runs on hundreds of processors, some of
which do, some of which don't.
Am 28.04.2025 um 13:15 schrieb Richard Damon:
NO, not all processors have a trap for divide by zero on integers, and
many that do allow the disabling of that trap.
Windows requires processors that can trap divisions by zero,
On Mon, 28 Apr 2025 14:28:41 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
Bonita Montero <Bonita.Montero@gmail.com> writes:
Am 28.04.2025 um 13:15 schrieb Richard Damon:
NO, not all processors have a trap for divide by zero on integers,
and many that do allow the disabling of that trap.
Windows requires processors that can trap divisions by zero,
No, Windows only runs on processors (x86) that happen to trap
divisions by zero. Linux runs on hundreds of processors, some of
which do, some of which don't.
Historically, Windows NT family of Windows OSes supported 6 different >architectures (or 8, depending of whether you consider AMD64 and
Aarch64 as different or the same as their 32-bit predecessors).
On Mon, 28 Apr 2025 14:28:41 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
Bonita Montero <Bonita.Montero@gmail.com> writes:
Am 28.04.2025 um 13:15 schrieb Richard Damon:
NO, not all processors have a trap for divide by zero on integers,
and many that do allow the disabling of that trap.
Windows requires processors that can trap divisions by zero,
No, Windows only runs on processors (x86) that happen to trap
divisions by zero. Linux runs on hundreds of processors, some of
which do, some of which don't.
Historically, Windows NT family of Windows OSes supported 6 different >architectures (or 8, depending of whether you consider AMD64 and
Aarch64 as different or the same as their 32-bit predecessors).
2 architectures architectures supported in the latest version (Win11).
IIRC, majority of those architectures can trap on integer division
by zero. Exceptions to that are Alpha and Itanium that *do not have*
integer division instructions. Alpha has floating-point division that
traps on zero. Itanium has no division instructions at all.
Thiago Adams writes:
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.
Division by a constant zero is a constraint violation in a context that >requires a constant expression.
I wrote this quick and dirty program:
#include <stdio.h>
#include <time.h>
int main(void) {
int one = time(NULL) / 1000000000;
int zero = one - 1;
int ratio = one / zero;
printf("%d\n", ratio);
}
It's not portable, but on the systems where I've tried it it sets
one to 1 and zero to 0 in a way that the compiler can't detect,
so the division won't be optimized away. (At least, it does so if
you run it between 2001 and 2286.)
On x86_64, it dies with a floating point exception.
On aarch64, it prints 0.
On Fri, 25 Apr 2025 12:05:13 -0700, Keith Thompson wrote:
Thiago Adams writes:
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.
Division by a constant zero is a constraint violation in a context that
requires a constant expression.
I wrote this quick and dirty program:
#include <stdio.h>
#include <time.h>
int main(void) {
int one = time(NULL) / 1000000000;
int zero = one - 1;
int ratio = one / zero;
printf("%d\n", ratio);
in math
1/0 has to be +infinite ( for approximation +INT_MAX for C?)
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.
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.
I'm not interested enough to read this whole long thread, but ISTR
that 1.0/0.0 on a '287 returns #inf - infinity.
#inf is sticky. If it's on your input it tends to be on your outputs.
Andy
Kaz Kylheku <643-408-1753@kylheku.com> writes:
On 2025-04-25, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
Thiago Adams <thiago.adams@gmail.com> writes:
Em 4/25/2025 4:05 PM, Keith Thompson escreveu:
Thiago Adams <thiago.adams@gmail.com> writes:
Does anyone know of any platform where integer division by zeroDivision by a constant zero is a constraint violation in a context
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. >>>>>
that requires a constant expression.
Consider this sample
int main(){
int a[1/0];
}
1/0 does not have a value in compile time,
So I believe compilers are making "a" a VLA because 1/0 is
not constant.
1/0 is not a constant expression.
A conforming compiler that supports VLAs (C99, or optionally C11 or
later) would make `a` a VLA, with undefined behavior at runtime when
1/0 is evaluated. For a conforming compiler that doesn't support
VLAs (C89/C90, or optionally C11 or later) the declaration is a
constraint violation.
My interpretation (looking at n3301) is that 1/0 is a constant
expression, which violates a constraint.
("Each constant expression shall evaluate to a constant that is in the
range of representable values for its type.")
The constraint makes it clear that there may be constant expressions
which evaluate out of range. (They are constant expressions in form:
constant operands, subject to the permitted operators.)
The constraint's purpose isn't to give a classifying requirement in the
sense that expressions not meeting the constraint are not taken to be
constant. It is for diagnostic use: constant expressions not meeting the >> constraint are to be diagnosed.
According to this interpretation the declarator a[1/0] would be deemed
to be a regular array, not VLA, and so a constraint violation occurs
regardless of VLA support.
Also looking at n3301, the syntax is:
constant-expression:
conditional-expression
That doesn't imply that all conditional-expressions are
constant-expressions. [...]