Re: integer divided by zero

Liste des GroupesRevenir à cl c 
Sujet : Re: integer divided by zero
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 25. Apr 2025, 21:31:25
Autres entêtes
Organisation : None to speak of
Message-ID : <87o6wkouea.fsf@nosuchdomain.example.com>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13)
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.

(But what old c89 compilers where doing in this case?)
>
This sample is a motivation to make integer divided by
zero a constrain.

I consider it motivation not to write code like that.

Sure, I wouldn't mind if using / or % with a right operand
that's a constant expression with value zero (either integer or
floating-point) were a constraint violation, but some compilers
are going to warn about it anyway, and I doubt that such a language
change would catch many errors.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

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