C++ Logo


Advanced search

Re: [std-proposals] Fwd: Use of volatile as function argument should not be deprecated.

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 10 Jun 2022 11:54:56 -0400
On Fri, Jun 10, 2022 at 11:10 AM Hyman Rosen <hyrosen_at_[hidden]> wrote:
> The "sense" that a program makes is given by the rules of the language,

No, the "sense" that a program makes lives in the head of an
individual programmer based on their general understanding of how a
language works. The details of what `volatile` means are extremely
esoteric and unknown to most working programmers. As such, doing this
will not make "sense" to them.

Which is the whole point here.

You're basically saying that extremely convoluted and rarely used
language rules should be something that every programmer knows and if
they don't know them, then the programmer is the one that's wrong. I
would prefer a language that doesn't require extremely convoluted and
rarely used language rules to solve problems.

>and the rules of the language have always said, since volatile was introduced, that reading or writing a volatile variable is a side effect that is sequenced with all other side effects, and that access to volatile variables is supposed to happen by following the abstract machine. The languages said nothing to differentiate automatic volatiles from any other volatiles.
> It is not esoteric nonsense to expect a program to behave the way the language specifies. And it is not as if the C++ committee hasn't added enormous amounts of esoteric nonsense to the language that people are expected to understand. Here's my favorite:
> int &a() { printf("a"); static int i; return i; }
> Int &b() { printf("b"); static int i; return i; }
> void foo() {
> a() <<= b();
> a() << b();
> a() < b();
> }

I'm not sure what exactly is "esoteric" (meaning "understood by or
meant for only the select few who have special knowledge or interest")
here. With the exception of whether the `static int i;` declaration
will zero-initialize `i`, there is nothing about this that I would
consider "esoteric". It's definitely weird, but it is a natural
outgrowth of:

1. How references work.
2. How local static variables work.
3. What those operators actually do.

None of which is particularly "esoteric". I would expect any C++
programmer who finished their first 6 months of study in the language
to be able to work out what this program does.

Received on 2022-06-10 15:56:23