🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.electronics.design
Article #1095

Re: Arms race

#1095
From: Don Y
Date: Thu, 12 Nov 2026 20:25
326 lines
17404 bytes
On 11/12/2026 9:36 AM, Waldek Hebisch wrote:
>>>> 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.

C's initial appeal was its simplicity (it is a SMALL language) and
"closeness to the hardware.

The first normative standard was essential because it created
THE language (instead of a collection of different interpretations
of the language).  And, codified things that should have been
defined earlier (function prototypes, the standard library).
It also HELPED the programmer with volatile, enum, signed,
void, const, etc.

But, every revision in beyond that seemed to be geared towards
the compiler vendor; allowing more and more leeway (usually
without any requirement to HELP the programmer).

Given that compilers run in resource rich environments and
tend to be (re)written fewer times than applications, this
seems a wrong emphasis.

And, given that the standard is free to say ANYTHING regarding
"requirements", it could just as easily have said "When encountering
undefined behavior, a loud klaxon should sound, accompanied by
blinkenlites and a complete refusal to emit ANY code, thus
drawing the programmer's attention to the "problem".

There should be a standard switch to say "go back to the prior
standard definition".  Etc.  Or, to flag any behavior that
may have changed since the last time you compiled this codebase.
How many people REALLY care about how long a build takes?
Can they not afford a faster development platform to provide
the speed they need, so the poor compiler writers don't have to
struggle so hard to speed up *their* programs?

Instead, the onus is put on the programmer to figure out how to
coax the compiler to emit code for sources that HAVE BEEN WORKING FOR
YEARS under prior compilers and language definitions.

A language is supposed to facilitate communication (in this case, of
ideas, concepts, constructs and mechanisms).  Instead, C has continued
to muddy the waters until folks will eventually abandon it (or, cling
to older versions that are better behaved).

> 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).

Have you ever tried to validate a substantial piece of software?
It is a grueling task and requires considerable expertise on both
sides of the table (client and provider).  Adding the *need* for
sophisticated language lawyers just makes that harder:
    "What happens if X+Y oveflows?  And, what about A+B?  C-D?  P*Q?"
Make a change to the codebase and repeat the exercise (esp if the
compiler has license to do code motion optimizations, etc.)

The original language had a relatively intuitive mapping onto the
hardware/machine language.  So, could be used as a shorthand for it,
saving all of those extra lines of ASM from having to be meticulously
inspected.  A modest piece of code is O(10KLoC).  If you were
reviewing the ASM associated with that, expect some multiple.

If the compiler is free to jigger things around so they don't
directly correspond to the C source, then good luck trying to
understand what the high level abstractions implemented by a
particular section of ASM might be.

[It's trivial to disassemble a piece of code.  Imagine trying to
figure out what it *does* from that disassembly, lacking a
direct "explanation" of each code section by the accompanying
"source"]

> 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 embedded system market generates more applications than
the desktop worl by orders of magnitude.  And, the desktop
world operates in a resource rich environment.  Along with
readily facilitating software revision and updates.  These
things aren't available in the embedded systems world -- where
people BUILD things and customers expect them to work.
(You don't even consider updating the software in your
refrigerator, microwave oven, mouse, keyboard, monitor,
doorbell, etc. because you would view that as an inconvenience
in their application)

So, some variant of C will be peeled off and maintained by a separate
standards organization.  This will force compiler writers to have
to support a second language (this is already in the works with
MISRA, C*, etc.).  How humiliating for a group charged with promoting
a language to see their market head off in a different direction...
BECAUSE of their actions!

>> 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.

No.  Even defined code gives the compiler vendor extra license.  The
code for:

    x = 5;
    print("hello");

need not perform those statements in that order.  So, I can compile
it on compiler A and come up with a different "sequence of operations"
(I'm being generous and giving them freedom in the details) than
on compiler B.

If I am *debugging* that bit of code, I most definitely care which
order the (ASM-associated) statements are executed, even if there is not
an implicit dependency *in* the source.

     x = 5;
     ...
     x += x;

can be replaced.  And, if x is never referenced, all of that code can
be elided.  And the compiler is under no obligation to TELL me that it
has done these things!  ("Oh!  I meant *y*, not *x*!")

Remember who the customer is.

>> 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

You aren't limited to using a K&R compiler to check the code's
syntax.  E.g., I make extensive use of KLEE which builds on LLVM
/to find bugs/.  But, use K&R/C89 to generate PRODUCTION code
that can be more readily validated.

> 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.

More use doesn't translate into better quality.

Remember, the goal is for the PROGRAMMER to be able to get his
algorithm to run on targeted hardware.  The compiler loses
all significance once the code is running.  And, can be
replaced by a competing product (or development methodology)
if it proves to be a hindrance to that goal.

> 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

But, they are under no obligation to do so!  As such, all
of that "help" can go away in the next release.

They also go too far in trying to treat standard library
functions as "operators" to be optimized like any other
statements.  E.g., I use NONE of the standard library function
names because I don't want the compiler second-guessing my intent.
Trust the programmer to be competent.  He doesn't need a "nanny".

> 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.

But you aren't *instructed* -- the compiler is under no obligation
to point out what you are doing wrong.  Instead, it can just
elide (or alter) your efforts with license.

I listened to a Mexican gentleman speaking about his wife, the
other day.  He kept using the pronoun "he/him" in every reference.
I could decide that I could ignore everything he was saying because
his grammar was incorrect -- that would surely be the easiest way
to interpret his comments.  Or, I can expend a bit of effort and
make the mental translation of he/him to she/her.

Apparently, compiler writers are too lazy to even make such an attempt.

[I could not correct him as I had no means of contacting him]

>> 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.

Because the specifications adopted for the compilers are nonsense
from the standpoint of the compiler's user!

C'mon, I'm not the only one singing this song:
  
<https://www.yodaiken.com/2021/05/19/undefined-behavior-in-c-is-a-reading-error/>
    <https://www.yodaiken.com/2021/05/16/c-is-not-a-serious-programming-language/>
    <https://www.kb.cert.org/vuls/id/162289/>
    <http://www.complang.tuwien.ac.at/papers/ertl17kps.pdf>
    <https://groups.google.com/g/boring-crypto/c/48qa1kWignU/m/o8GGp2K1DAAJ>
    <http://homes.cs.washington.edu/~akcheung/getFile.php?file=apsys12.pdf>

The standards committee has placed an emphasis on "compiler tricks"
at the expense of maintaining a usable language.

And, falling back on standards language to justify their excesses.

> 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.

What counts is whether or not the code faithfully implements the
algorithm created by the developer.  Because the developer will be TESTING
and DEBUGGING to those expectations, not the compiler writer's view of
what he *should* have written.

> 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.
The compiler understands the target hardware.  The preprocessor
(assuming you are trying to write portable code) only understands
the language syntax and the application.

So, you promote the optimizations that the developer would freely
embrace to the sources via the preprocessor as a bridge between what
the developer wants to say and what the code should realistically do
(e.g., char SSN[3 +1+ 2 +1+ 4 +1] is much cleaner to write than
SSN[12] or, gasp, SSN[11])

Expecting the developer to write code that understands and exploits
how the processor issues opcodes defeats the purpose of having a HLL.
Technical Details
Message-ID: <11d57b7$94ph$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
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> <11d4pum$nurs$1@paganini.bofh.team>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Don Y <blockedofcourse@foo.invalid>
Newsgroups: sci.electronics.design
Subject: Re: Arms race
Date: Thu, 12 Nov 2026 13:25:06 -0700
Organization: A noiseless patient Spider
Lines: 326
Message-ID: <11d57b7$94ph$1@dont-email.me>
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>
 <11d4pum$nurs$1@paganini.bofh.team>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 12 Nov 2026 20:25:12 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="299825"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/ZiH0yUVj42jS/PgzezxqQ"; posting-host="48e15282b0dd10fa3938541b9bac36fa"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ANQQOwJqC1qNvgR2QscP1xoyPRw= sha256:yoczXc0RyD6QuXDo41m5JSJkkg3bYrqQDhvclB0/VtE=
	sha1:UopbiPZJ05bZWmmJic4ySsj/HA8= sha256:Hj/y/gLTfpTPEsyRtrCrsqmPXm6ulZsG+RaiG+0WWxU=
Content-Language: en-US
In-Reply-To: <11d4pum$nurs$1@paganini.bofh.team>