Article View: sci.electronics.design
Article #1085Re: Arms race
From: Waldek Hebisch
Date: Thu, 12 Nov 2026 16:36
Date: Thu, 12 Nov 2026 16:36
157 lines
9047 bytes
9047 bytes
Don Y <blockedofcourse@foo.invalid> wrote:
> On 11/9/2026 2:14 PM, Waldek Hebisch wrote:
>> Don Y <blockedofcourse@foo.invalid> wrote:
>>> On 11/8/2026 12:27 PM, Waldek Hebisch wrote:
>>>> You clearly go into area were you are not an expert. Google a
>>>> bit about "undefined behaviour" in C and you will learn that
>>>> when source code makes no sense, then C compier can do
>>>> essentially anything, which in not so rare cases means that
>>>> compiler simply deletes what programmer wrote. Explicit nop-s
>>>
>>> The compiler doesn't have THAT much license. It can't decide to
>>> implement arbitrary operations just because you APPEAR to be
>>> relying on a behavior that is undefined.
>>
>> Compiler just uses rules, so writing about appearence makes no
>> sense. When optimizing compier performs a lot of transformations.
>> Validity of transformations may depend on conditions. When
>> checking conditions compiler assumes that program does not
>> contain undefined behaviour.
>>
>> And yes, C standard gives such freedom to authors of C
>> compilers:
>>
>> : undefined behavior
>> : behavior, upon use of a nonportable or erroneous program construct
>> : or of erroneous data, for which this document imposes no requirements
>>
>> Do I need to explain to you what "no requirements" mean?
> No one (responsibly) builds things using modern C. Because
> it is not a "practical" (as in "suitable for PRACTICE") language.
The "problem" first appeared in context of optimizing Fortran
compliers and AFAIK while wording is different and specific
conditions differs in effect Fortran standard allows the
same. Also Pascal standard. IIUC Ada mandates runtime checks
for a lot of things and many other things lead to compile time
errors. But programmer determided to write programs in C
style still can inject equivalent of undefined behaviour with
consequences the same as in C.
AFAIK a lot of folks use C for important software. Some claim
that their code contains no bugs, so in particular no undefiend
behaviour. Some use tools like CompCert. IIUC some safety
standard certify _object_ code, it does not matter how good or
buggy is C compiler that generated object code, you are
supposed to review generated code and verify that it is doing
what it is supposed to do (and presumably you need to keep
appropriate document trail to show that you really did that).
Some people think that software is serious when it brings money
to its creators. AFAIK most optimizations in gcc and clang
are funded by commercial companies which see gains from
those optimizations. Most of this is motivated by C++,
where you really need those optimizations for decent speed.
But problems with undefined bahaviour are almost the same.
> The same bit of source code written in a particular language
> should result in the same general behavior regardless of processor
> or compiler choice.
It will, if it is defined code.
> That contract was broken by C more than 20 years ago.
>
> C is now an academic exercise and playground for c.l.c types.
>
> All of my colleagues use C89 or K&R -- because we have to be able
> to PROVE that the source code that the customer receives and
> systematically reviews corresponds with what is happening in the
> hardware.
Use of K&R C for new code looks irresponsible to me: checking that
code accepted by K&R compiler has no bugs is more effort than
the same for modern C. C89 looks reasonable, but it gains you
a little. Main thing are compilers. There are two mainstream
ones with multiple targets, that is gcc and clang. There were
few respectable compilers from specific vendors targeting their
targets, but most seem to be gone now. And all compilers beside
gcc and clang seem to get much less use and consequently are
less tested.
When using C compiler you may have trouble for various reasons.
One thing are ordinary bugs in C code. Other thing are bugs
which cause undefined behaviour. Third thing are compiler bugs,
when source code is well defined, but compiler produces wrong
object code. AFAICS modern compilers are much more helpful
with catching ordinary bugs. Concerning wrong code, they
seem to be better, but larger size of compiler and increased
complexity may leave some doubts. Undefined behaviour could
catch you even 35 years ago: at that time users complained
that their working code is broken by new C compilers. Users
learned that old code was wrong and how to write correct
code. I do not see much difference now: you learn to write
code in a different way, which has additional advantage that
code avoinding risky constructs usually is also clearer.
> Any "optimizations" have to be relatively trivial and intuitive
> and visible at the preprocessor stage; the preprocessed output
> should accuraely define what the code ACTUALLY does, not what the
> developer HOPES it will do (subject to the compiler-writer's
> whims).
You preach specifications yet you have trouble that compiler also
have specification. Stay withing specified (defined) constructs
and your code will have expected effect. If you expect more
than is specified, then you expect too much.
Concerning "what the code ACTUALLY does", I expect compiler
to delete checks that are known to pass at compile time
(such checks may be generated from macros and I want to keep
my macros). I expect compiler to expand inline simple functions,
when it leads to smaller code size. In general generated
code may look quite different than expectation of some
folks. What counts is the effect.
For delay loop I have assembly code: C compiler may and should
collapse to nothing loops that take time but otherwise do not
contribute to the result. And I find atempts to cripple
optimization in order to preserve delay loop to be too
unreliable. But otherwise C allows me to write what
should be done and compiler generates appropriate code.
> Loop unrolling, function inlining, constant folding, constant
> subexpression elimination, etc. -- all things that are OBVIOUS to
> someone inspecting the source ("Yes, I understand that STRINGLENGTH+1
> is intended to account for the NUL termination in a more visible manner"
> or "OK, I see 3+3+4+1 is a good way of representing a telephone number"
> or "Yeah, I guess you could do those steps N (constant) times in a row
> instead of wrapping them in a loop that is executed N times")
>
> In that way, the "source" is a writing shorthand but one that still
> completely constrains the implementation.
>
> E.g., I use a construct:
> object=>method(arguments)
> liberally in my code. The language doesn't support it (of course).
> But, it is known to be a representational shorthand -- something to
> unclutter the code and highlight the actual operation being performed.
>
> There is no surprise when you look at the preprocessor output...
> for ANY instance of such an expression.
>
> Even the optimizing IDL compiler is obvious in the "optimizations"
> that it makes (e.g., choosing effective marshalling sequences instead
> of leaving that up to the developer)
That is slightly different thing. Optimizations require some effort.
If you have preprocessor/precompiler it makes no sense to duplicate
optimizations done by C compiler. Only things that C compiler
can not optimize are worth optimization in a precompiler and only
when they are important enough. More optimizations in C compiler
means that your precompiler may be simpler. For example
precompiler may naively insert code trusting that C compiler
will remove it in cases where it is not needed.
--
Waldek Hebisch
Technical Details
Message-ID:
<11d4pum$nurs$1@paganini.bofh.team>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!paganini.bofh.team!not-for-mailReferences:
<11bp6d1$16i93$1@dont-email.me> <11c0065$3hr4g$1@dont-email.me> <39e9elp8cqum5iatg21ltbf06hc4p4dgec@4ax.com> <eig9ellto4nl35n0cd8elct4boi2018mcp@4ax.com> <11ck9s9$2dmvp$1@dont-email.me> <fe8selhl8um5p168shk979cms2elurlhh1@4ax.com> <11cma06$34o3u$2@dont-email.me> <4rbtelp38pp2qnaqha6cq7csbfafpgk9i9@4ax.com> <11cmffm$36ee0$1@dont-email.me> <11cqieb$3h7vq$2@paganini.bofh.team> <11cqnt0$mtaq$1@dont-email.me> <11ctd4b$3rem1$1@paganini.bofh.team> <11d2msa$3dn7v$3@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
From: antispam@fricas.org (Waldek Hebisch)
Newsgroups: sci.electronics.design
Subject: Re: Arms race
Date: Thu, 12 Nov 2026 16:36:40 -0000 (UTC)
Organization: bofh.team Usenet service
Message-ID: <11d4pum$nurs$1@paganini.bofh.team>
References: <11bp6d1$16i93$1@dont-email.me> <11c0065$3hr4g$1@dont-email.me> <39e9elp8cqum5iatg21ltbf06hc4p4dgec@4ax.com> <eig9ellto4nl35n0cd8elct4boi2018mcp@4ax.com> <11ck9s9$2dmvp$1@dont-email.me> <fe8selhl8um5p168shk979cms2elurlhh1@4ax.com> <11cma06$34o3u$2@dont-email.me> <4rbtelp38pp2qnaqha6cq7csbfafpgk9i9@4ax.com> <11cmffm$36ee0$1@dont-email.me> <11cqieb$3h7vq$2@paganini.bofh.team> <11cqnt0$mtaq$1@dont-email.me> <11ctd4b$3rem1$1@paganini.bofh.team> <11d2msa$3dn7v$3@dont-email.me>
Injection-Date: Thu, 12 Nov 2026 16:36:40 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="785276"; mail-complaints-to="usenet@bofh.team"; posting-host="d028f9ad2fa2c51f22dbfed0d81d7daf"; posting-account="69e66f1681224ab92235b464ce7a90b6"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
X-Postfilter: Postfilter-NG 2026.10.2