Related articles |
---|
[28 earlier articles] |
Re: Undefined Behavior Optimizations in C Keith.S.Thompson+u@gmail.com (Keith Thompson) (2023-01-20) |
Re: Undefined Behavior Optimizations in C anton@mips.complang.tuwien.ac.at (2023-01-21) |
Re: Undefined Behavior Optimizations in C 864-117-4973@kylheku.com (Kaz Kylheku) (2023-01-22) |
Re: Undefined Behavior Optimizations in C anton@mips.complang.tuwien.ac.at (2023-01-22) |
Re: Undefined Behavior Optimizations in C martin@gkc.org.uk (Martin Ward) (2023-01-23) |
Re: Undefined Behavior Optimizations in C gah4@u.washington.edu (gah4) (2023-01-23) |
Re: Undefined Behavior Optimizations in C dave_thompson_2@comcast.net (2023-01-28) |
From: | dave_thompson_2@comcast.net |
Newsgroups: | comp.compilers |
Date: | Sat, 28 Jan 2023 10:35:18 -0500 |
Organization: | A noiseless patient Spider |
References: | 23-01-009 23-01-011 23-01-012 23-01-017 23-01-027 23-01-032 |
Injection-Info: | gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="12030"; mail-complaints-to="abuse@iecc.com" |
Keywords: | C, Fortran, history |
Posted-Date: | 29 Jan 2023 11:56:51 EST |
On Tue, 10 Jan 2023 17:32:28 +0100, David Brown
<david.brown@hesbynett.no> wrote:
[ UB example: generated code assumes bool parameter is only 0 or 1 and
mishandles anything else, but misdeclared call passes 2 ]
> This is clearly wrong - clearly undefined behaviour. And the result
> would be a formatted disk. But there is nothing wrong with the
> compiler's generated code. I have seen other occasions when compiler's
> have made code with booleans that appear to be both true and false, or
> neither true nor false, as a result of undefined behaviour setting the
> underlying memory to something other than 0 or 1, simply because that
> was the result of the most efficient code.
>
FWIW -- back in the 80s the VAX FORTRAN compiler checked only the _low
bit_ of a LOGICAL variable (stored as a byte or a 4-byte word, I
forget which) because this was faster. People often reused (scarce and
expensive) memory then and such a variable might accidentally get set
to a value other than 0 or 1, producing surprising/confusing results.
In those days DEC was vigorously opposing C (they had BLISS instead)
and Unix, so there was no DEC C compiler, though I'm pretty sure there
was a DECUS (user group) one, and of course there was not yet a C
standard at all much less one including bool.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.