Liste des Groupes | Revenir à cl c |
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 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.
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. [...]
Les messages affichés proviennent d'usenet.