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) |
[7 later articles] |
From: | Spiros Bousbouras <spibou@gmail.com> |
Newsgroups: | comp.compilers |
Date: | Fri, 7 Jan 2022 13:21:29 -0000 (UTC) |
Organization: | A noiseless patient Spider |
References: | <17d70d74-1cf1-cc41-6b38-c0b307aeb35a@gkc.org.uk> 22-01-016 22-01-018 22-01-020 |
Injection-Info: | gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="30860"; mail-complaints-to="abuse@iecc.com" |
Keywords: | standards, semantics |
Posted-Date: | 07 Jan 2022 20:25:13 EST |
In-Reply-To: | 22-01-020 |
On Thu, 6 Jan 2022 16:43:05 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
> David Brown <david.brown@hesbynett.no> schrieb:
>
> > There is no need to memorize undefined behaviours for a language -
> > indeed, such a thing is impossible since everything not defined by a
> > language standard is, by definition, undefined behaviour. (C and C++
> > are not special here - the unusual thing is just that their standards
> > say this explicitly.)
>
> This is a rather C-centric view of things. The Fortran standard
> uses a different model.
>
> There are constraints, which are numbered. Any violation of such
> a constraint needs to be reported by the compiler ("processor",
> in Fortran parlance). If it fails to do so, this is a bug in
> the compiler.
>
> There are also phrases which have "shall" or "shall not". If this
> is violated, this is an error in the program. Catching such a
> violation is a good thing from quality of implementation standpoint,
> but is not required. Many run-time errors such as array overruns
> fall into this category.
This seems to me exactly like the C model. What difference do you see ?
Regarding the more general issue, it seems to me that undefined behaviour is
a red herring (which I think is the point David was making). Every time one
writes code in any language , one must have an expectation on how the code is
supposed to behave and some reasoning on why the code they wrote will behave
according to their expectations. The reasoning will be based (apart from
general rules from logic and mathematics) on what the standard of the
programming language specifies (if the language has a standard) , what the
translator/compiler documentation specifies , what the documentation of any
libraries they use specifies and so forth.
For example lets say that I write in C
int a = INT_MAX + 1 ;
with the expectation that a will get the value INT_MIN. The onus is on me
to provide a reasoning why the code above will meet my expectation. If I
cannot provide such a reasoning then from my point of view the code is
already undefined. The fact that the C standard also says that the code is
undefined is irrelevant. Even if the C standard specified for example that
signed integer arithmetic uses wraparound, unless I could point to the place
in the standard where it said so, the code is still undefined from my point
of view so I should not use it.
But lets say that I have the above code and I intend to compile it with
GCC using the -fwrapv flag. Then my expectation is actually justified
based on the GCC documentation for what -fwrapv means and the parts
of the C standard which define what the various symbols in
int a = INT_MAX + 1 ;
mean. I'm not going to provide a proof because it should be obvious. But
any such proof would not need to cite any part of the C standard which
explicitly mentions undefined behaviour.
The only occasion where an explicit mention of undefined behaviour would be
relevant would be if the C standard (or any standard) were contradictory i.e.
it said in some place that some construct has a certain defined behaviour and
it said in some other place that the same construct has undefined behaviour.
But with a popular language like C , if such contradictions existed , they
would be caught early and corrected.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.