Re: integer divided by zero

Liste des GroupesRevenir à cl c 
Sujet : Re: integer divided by zero
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.c
Date : 14. May 2025, 09:09:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86wmajvcj4.fsf@linuxsc.com>
References : 1 2 3 4 5 6
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

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

Based on a memory of reading an old Defect Report (sorry don't know
which one), I think there was an official statement to the effect
that any conditional-expression is also a constant-expression, but
the constraints aren't in force unless the surrounding context
requires a constant-expression.  In other words whether something is
a constant-expression is purely a local syntactic condition;  the
conditions stated for constant expressions matter only when being
a constant expression is necessary to satisfy some other rule in
the C standard.


Date Sujet#  Auteur
25 Apr 25 * integer divided by zero46Thiago Adams
25 Apr 25 +* Re: integer divided by zero6David Brown
25 Apr 25 i`* Re: integer divided by zero5Thiago Adams
25 Apr 25 i `* Re: integer divided by zero4Keith Thompson
26 Apr 25 i  `* Re: integer divided by zero3Thiago Adams
26 Apr 25 i   `* Re: integer divided by zero2Kenny McCormack
26 Apr 25 i    `- Re: integer divided by zero1Kaz Kylheku
25 Apr 25 +* Re: integer divided by zero9Keith Thompson
25 Apr 25 i+* Re: integer divided by zero6Thiago Adams
25 Apr 25 ii`* Re: integer divided by zero5Keith Thompson
25 Apr 25 ii +* Re: integer divided by zero3Kaz Kylheku
26 Apr 25 ii i`* Re: integer divided by zero2Keith Thompson
14 May 25 ii i `- Re: integer divided by zero1Tim Rentsch
28 Apr 25 ii `- Re: integer divided by zero1Thiago Adams
30 Apr 25 i`* Re: integer divided by zero2Rosario19
30 Apr 25 i `- Re: integer divided by zero1David Brown
25 Apr 25 +- Re: integer divided by zero1John McCue
26 Apr 25 +- Re: integer divided by zero1Waldek Hebisch
27 Apr 25 +* Re: integer divided by zero24Bonita Montero
27 Apr 25 i+* Re: integer divided by zero11Bonita Montero
27 Apr 25 ii`* Did you get confused again? You seem eaily bewildered. (Was: integer divided by zero)10Kenny McCormack
27 Apr 25 ii `* Re: Did you get confused again? You seem eaily bewildered. (Was: integer divided by zero)9Bonita Montero
27 Apr 25 ii  +* Re: Did you get confused again? You seem eaily bewildered. (Was: integer divided by zero)3Kaz Kylheku
27 Apr 25 ii  i+- Re: Did you get confused again? You seem eaily bewildered. (Was: integer divided by zero)1Bonita Montero
28 Apr 25 ii  i`- Re: Did you get confused again? You seem eaily bewildered.1Waldek Hebisch
28 Apr 25 ii  +* Re: Did you get confused again? You seem eaily bewildered.3Waldek Hebisch
30 Apr 25 ii  i+- Re: Did you get confused again? You seem eaily bewildered.1Rosario19
30 Apr 25 ii  i`- Re: Did you get confused again? You seem eaily bewildered.1Richard Heathfield
28 Apr 25 ii  `* Re: Did you get confused again? You seem eaily bewildered.2Waldek Hebisch
28 Apr 25 ii   `- Re: Did you get confused again? You seem eaily bewildered.1Bonita Montero
28 Apr 25 i+* Re: integer divided by zero4Richard Heathfield
28 Apr 25 ii`* Re: integer divided by zero3Bonita Montero
28 Apr 25 ii `* Re: integer divided by zero2Richard Heathfield
28 Apr 25 ii  `- Re: integer divided by zero1Bonita Montero
28 Apr 25 i`* Re: integer divided by zero8Richard Damon
28 Apr 25 i +* Re: integer divided by zero5Bonita Montero
28 Apr 25 i i+- Re: integer divided by zero1Bonita Montero
28 Apr 25 i i`* Re: integer divided by zero3Michael S
28 Apr 25 i i +- Re: integer divided by zero1Bonita Montero
28 Apr 25 i i `- Re: integer divided by zero1Muttley
28 Apr 25 i `* Re: integer divided by zero2Waldek Hebisch
28 Apr 25 i  `- Re: integer divided by zero1Bonita Montero
28 Apr 25 +* Re: integer divided by zero2Richard Heathfield
28 Apr 25 i`- Re: integer divided by zero1Keith Thompson
3 May 25 `* Re: integer divided by zero2Vir Campestris
3 May 25  `- Re: integer divided by zero1Michael S

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal