Related articles |
---|
Re: what is defined, was for or against equality tkoenig@netcologne.de (Thomas Koenig) (2022-01-06) |
Re: what is defined, was for or against equality david.brown@hesbynett.no (David Brown) (2022-01-07) |
Re: what is defined, was for or against equality spibou@gmail.com (Spiros Bousbouras) (2022-01-07) |
Re: what is defined, was for or against equality tkoenig@netcologne.de (Thomas Koenig) (2022-01-08) |
Re: what is defined, was for or against equality spibou@gmail.com (Spiros Bousbouras) (2022-01-08) |
Re: what is defined, was for or against equality tkoenig@netcologne.de (Thomas Koenig) (2022-01-09) |
Re: what is defined, was for or against equality spibou@gmail.com (Spiros Bousbouras) (2022-01-09) |
Re: what is defined, was for or against equality david.brown@hesbynett.no (David Brown) (2022-01-09) |
Re: what is defined, was for or against equality tkoenig@netcologne.de (Thomas Koenig) (2022-01-10) |
Re: what is defined, was for or against equality gah4@u.washington.edu (gah4) (2022-01-10) |
Re: what is defined, was for or against equality david.brown@hesbynett.no (David Brown) (2022-01-11) |
Re: what is defined, was for or against equality 480-992-1380@kylheku.com (Kaz Kylheku) (2022-01-11) |
Re: what is defined, was for or against equality gah4@u.washington.edu (gah4) (2022-01-11) |
[3 later articles] |
From: | Spiros Bousbouras <spibou@gmail.com> |
Newsgroups: | comp.compilers |
Date: | Sun, 9 Jan 2022 21:30:13 -0000 (UTC) |
Organization: | A noiseless patient Spider |
References: | 22-01-016 22-01-018 22-01-020 22-01-027 22-01-032 22-01-034 22-01-035 |
Injection-Info: | gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="30306"; mail-complaints-to="abuse@iecc.com" |
Keywords: | Fortran, standards, comment |
Posted-Date: | 09 Jan 2022 16:53:26 EST |
In-Reply-To: | 22-01-035 |
On Sun, 9 Jan 2022 00:09:19 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
> Spiros Bousbouras <spibou@gmail.com> schrieb:
> > On Sat, 8 Jan 2022 09:31:06 -0000 (UTC)
> > Thomas Koenig <tkoenig@netcologne.de> wrote:
> >> I see C conflating two separate concepts: Programm errors and
> >> behavior that is outside the standard. "Undefined behavior is
> >> always a programming error" does not work; that would make
>
> > The C standard is in no position to say that some programme is in
> > error. This would require near omniscience from the standard
> > writers.
>
> A standard (or other specification document) is certainly able to
> state that some construct is in error. To grab an often-quoted
> example:
>
> J3/18-007r1, the Fortran 2018 interpretation documents, states in
> subclause 9.5.3, "Array elements and array sections",
>
> # The value of a subscript in an array element shall be within the
> # bounds for its dimension.
>
> No omnicience required to write or understand that sentence.
>
> This puts the burden on the programmer. The compiler might catch
> such an error error and abort the program, or other unpredictable
> things such as overwriting an unrelated variable might also happen.
I haven't read any Fortran standards so I can only go by the above quote.
Only the programmer knows what their requirements are and why they think that
the code they wrote will meet those requirements. My idea of error is that
either the code does not meet the requirements or it does so only by accident
and the programmer does not have a correct reasoning as to why their code
will meet those requirements. You seem to be reading the quote as saying
No matter what the programmer requirements and no matter what extensions
their Fortram implementation offers , the programmer requirements will
not be justifiably met if they use an array subscript outside the bounds
for its dimension.
Perhaps some Fortran implementation gives information as to the layout of
distinct variables so that one knows what will be overwritten by writing off
the bounds of some aray and it will be overwritten in the way the programmer
wants. Unlikely (especially for Fortran) but it cannot be excluded. I can
imagine a C implementation for small embedded systems which does provide such
information and a programmer using it to reduce the number of instructions to
achieve a desired result. A more realistic example is the following :
#include <stdio.h>
int main(void) {
int a = 12 , b = 14 ;
printf("%2$d %1$d\n" , a , b) ;
return 0 ;
}
The above code has undefined behaviour according to the C standard. It is
defined according to POSIX .Whether it is in error depends on whether the
programmer really wanted to print
14 12
and no standards committee can possibly know this. So I still think that your
reading requires omniscience from the Fortran standard writers. But perhaps
there are other parts of the standard which justify your reading. For example
some parts of the Common Lisp standard do state that an implementation must
not extend some construct to provide useful functionality beyond what the
standard specifies. I don't remember precisely how it states it and I can't
find those parts now.
> Reading a language standard can be hard. Quite often, information
> is scattered throughout the text and needs to be pieced together
> to find the necessary information, especially definition of terms
> which are crucial to understanding. Most programmers do do not
> read standards (at least final committee drafts can usually be
> found these days on the Internet), but compiler writers should at
> least be familiar with what they are implementing.
>
> Programmers often rely on books, but these can also get things wrong.
C books at least usually don't go into the fine details of undefined
behaviour. To hone one's instincts in this area one should spend a few
months systematically reading comp.lang.c while consulting a draft
of the standard !
> Because programmers are human, they also can get ticked off when being
> told that a construct they have used for years has been illegal
> for decades :-|
This may happen but my impression with C is that the strongest complaints
come from people who
- have read the C standard (or at least the relevant parts of it)
- know that their code has undefined behaviour and know what the term means
- they do not rely on any compiler extensions
yet still feel certain (dare I say "entitled" ?) that their code ought to
behave in a certain way. For an extreme example see Robert M. Hyatt of
crafty fame (a chess programme which has won awards in the past) :
http://www.open-chess.org/viewtopic.php?f=5&t=2519 .
[Fortran used to require that arrays were stored in column major order, that
double precision took twice the space of real and integer, and you were allowed
to use EQUIVALENCE and adjustable dimensions in argument arrays to do overlaying
assuming that layout. Dunno how much more modern Fortran has deprecated it. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.