On Mon, 30 Nov 2026 13:29:50 -0000 (UTC) Thomas Koenig <tkoe…@netcologne.de> wrote:
> Dan Cross <cro…@spitfire.i.gajendra.net> schrieb: >
> > Rules for undefined behavior in Fortran obviously different from > > those of C, since Fortran is a different langauge.
> > Fortran has not concept of undefined behavior in the standard per se. > It has correct code, code that violates numbered constraints (which > require a diagnostic) and code that violates a "shall" directive, > which is errouneous but for which no diagnostic is required. > > Integer overflow is among the restrictions that a processor (Fortran > standardese for the combination of compiler, run-time system etc) is > not required to catch, a.k.a. the programmer's fault. And Fortran > allows reassociation as long as parentheses are not violated.
In more simple words, in case of arithmetic operations on signed integers there is no semantical difference between C and Fortran.
> > > > C came up in this context as a parenthetical, "if one considers > > the assembly equivalent of this...". Here, it was clear that C > > syntax was merely used as a pseudocode. Arguments about C's > > behavior and definition are beside the point.
> > There are a few points to consider here. Gcc is fairly C-centric, > even now. Also, tools like the sanitizers could cause problems > with integer reassociation. > > But I have been thinking about introducing a -freassoc-integer > flag to gcc, and enabling it by default by gfortran. Maybe at > the beginning of stage 1 for gcc 18. >