Related articles |
---|
[14 earlier articles] |
Re: Undefined Behavior Optimizations in C david.brown@hesbynett.no (David Brown) (2023-01-11) |
Re: Undefined Behavior Optimizations in C david.brown@hesbynett.no (David Brown) (2023-01-11) |
Re: Undefined Behavior Optimizations in C gah4@u.washington.edu (gah4) (2023-01-11) |
Re: Undefined Behavior Optimizations in C 864-117-4973@kylheku.com (Kaz Kylheku) (2023-01-12) |
Re: Undefined Behavior Optimizations in C Keith.S.Thompson+u@gmail.com (Keith Thompson) (2023-01-12) |
Re: Undefined Behavior Optimizations in C tkoenig@netcologne.de (Thomas Koenig) (2023-01-12) |
Re: Undefined Behavior Optimizations in C antispam@math.uni.wroc.pl (2023-01-13) |
Re: Undefined Behavior Optimizations in C 864-117-4973@kylheku.com (Kaz Kylheku) (2023-01-15) |
Re: Undefined Behavior Optimizations in C spibou@gmail.com (Spiros Bousbouras) (2023-01-18) |
Re: Undefined Behavior Optimizations in C david.brown@hesbynett.no (David Brown) (2023-01-18) |
Re: Undefined Behavior Optimizations in C gah4@u.washington.edu (gah4) (2023-01-18) |
Re: Undefined Behavior Optimizations in C alexfrunews@gmail.com (Alexei A. Frounze) (2023-01-19) |
Re: Undefined Behavior Optimizations in C gah4@u.washington.edu (gah4) (2023-01-20) |
[8 later articles] |
From: | antispam@math.uni.wroc.pl |
Newsgroups: | comp.compilers |
Date: | Fri, 13 Jan 2023 20:46:28 -0000 (UTC) |
Organization: | Aioe.org NNTP Server |
References: | 23-01-009 23-01-011 23-01-012 23-01-017 23-01-018 23-01-021 |
Injection-Info: | gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="18899"; mail-complaints-to="abuse@iecc.com" |
Keywords: | C, Fortran, comment |
Posted-Date: | 13 Jan 2023 16:21:12 EST |
X-Notice: | Filtered by postfilter v. 0.9.2 |
Spiros Bousbouras <spibou@gmail.com> wrote:
> On Fri, 6 Jan 2023 10:33:29 -0800 (PST)
> gah4 <gah4@u.washington.edu> wrote:
> > It turns out, though, to have a fair number of statements like:
> >
> > IF(I.GT.0.AND.X(I).EQ.3) ...
> >
> > That is, test the subscript and use it in the same IF statement.
> >
> > Now, this would not be a problem at all in C, with short-circuit IF
> > evaluation required, but even now Fortran doesn't do short
> > circuit IF evaluation. ...
>
> The analogous C code would be
> if (I > 0 && X[I] == 3) ...
No, Fortran array start from 1, C arrays start from 0. And Fortran
is not obliged do do short circuit evaluation. So analogous
C code would be
char bv1 = (I>=0);
char bv2 = (X[I] == 3);
if (bv1 && bv2) ...
I this code compiler may throw out 'bv1' (assume that it is true).
Of course, normal C programmer would write
if ((I>=0)&&(X[I] == 3))
which is fine due to short circuit evaluation. Reversing order:
if ((X[I] == 3)&&(I>=0))
have the same problem as first version. Both first version and
third version may appear as output of generators or due to macro
expansion, so this is not entirely theoretical problem. OTOH,
in Fortran and Pascal classic teaching was "do not do this".
This was particularly important in Pascal, as standard required
full evaluation.
--
Waldek Hebisch
[You can start Fortran arrays at zero if you want
DIMENSION FOO(0:99)
But I agree mostly people use the 1 default -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.