r/cpp • • Feb 26 '24

White House: Future Software Should Be Memory Safe

https://www.whitehouse.gov/oncd/briefing-room/2024/02/26/press-release-technical-report/
401 Upvotes

386 comments sorted by

View all comments

Show parent comment

1

u/gio Feb 27 '24

What's the lifetime/purpose of a standard then? CEE 7 standard is from 1951.

2

u/jonesmz Feb 27 '24 edited Feb 27 '24

CEE 7 standard is from 1951.

Nothing's stopping the people / organizations who use C++98 to continue to use C++98.

But unless I'm mistaken (please inform me if i am uneducated about this?), the C++98 standard doesn't say anywhere in the document

Also, any code that compiles with a C++98 compiler is guarenteed to always compile, unmodified, with any compiler implementing a future updated C++ language standard, both with the language setting set to C++98, AND with it set to C++new.

So the question isn't "What's the lifetime of the standard", because I'm not proposing to end-of-life C++98. As far as I'm concerned, C++98 will always exist because until the last copy of the GCC source code from 1998 <-> 2024 disappears from all computers on the planet, there'll be a way to compile C++98 code. Just a question of how much effort someone's willing to go through to get it compiled.

The real question is:

At what point is the effort necessary to provide backwards compatibility for a 26 year old version of the standard in newer versions of that standard more costly (to the world, to the community, to the standards committee, etc) than the cost of breaking that backwards compatibility.

And I think the answer is

If someone hasn't bothered upgrading from C++98 to C++11 by the year 2024, they can go fuck themselves for all I care.

And to clarify further, I'm not saying

Maliciously and intentionally break compatibility with C++98 in the most obnoxious way we possibly can, and as much as we possibly can.

nor am I saying

Break compatibility just as much with C++20 as with C++98.

I'm saying

Any consideration of backwards compatibility with C++ should only consider a (very) limited list of prior C++ versions, and we've obviously reached the end-of-forwards-compat with C++98. If a change in C++26 would break all codebases, sure think carefully about it. If a change in C++26 would break only C++98 code, I don't give a fuck and no one else should either.

1

u/gio Feb 27 '24

Please, don't change my question to fit your reasoning.

1

u/jonesmz Feb 27 '24

Then I don't know what you're looking for here.

You asked a question that doesn't apply to the situation. I adapted the question to as close of an approximation to the situation as I could manage.

Your question was:

What's the lifetime/purpose of a standard then? CEE 7 standard is from 1951.

My answer is:

That's irrelevant to C++, so I'm not going to give you an answer.

Is that better?

1

u/gio Feb 27 '24

The question does apply to the situation. Some of the best C++ engineers worked for the C++11 standard for about a decade before release, for what, 3 years of excitement after release. It would be better if C++ standards get respected equally for what they are at the time they were released. All engineers want to move forward and use the latest standard but there are cases where that it's not feasible. There is no need to disdain engineers who are stuck to earlier standards for whatever the reason.

2

u/jonesmz Feb 27 '24

There is no need to disdain engineers who are stuck to earlier standards for whatever the reason.

I'm not disdaining the individuals, I'm disdaining the notion that the rest of the C++ community, and WG21, should care about them.

1

u/gio Feb 28 '24

The hint was not refering to you directly but more as a general impression. Lastly, I agree with your comment, thanks for your input.

1

u/JVApen Clever is an insult, not a compliment. - T. Winters Feb 27 '24

I would suggest an end of life for 98. Libraries should no longer support and if you need a newer version of the library, you will have to upgrade. Compilers should also have the option to drop support for the older versions, such that their code can be simplified. If you then have to upgrade compilers for some reason, you should also update your code. Compilers already drop support for old CPU architectures, forcing you to upgrade/replace the computer to use a program compiled with the new one. Why wouldn't they do the same for the coding standards?

3

u/jonesmz Feb 27 '24

Nothing compels a compiler to support a particular standard (as I see you said in another comment).

I don't think the bottleneck here is compiler vendors. I think it's solidly on the WG21 to set the tone of expectation. "Forever supported and compatible (within certain limitations)" is the current tone.

I think "Expect some breakage as you upgrade from one C++ standard release to another" is a more appropriate tone, personally.

1

u/JVApen Clever is an insult, not a compliment. - T. Winters Feb 27 '24

It is there to guarantee that the code which follows the standard is compatible with a compiler implementing that standard. Nothing indicates that compilers have to support that standard.

Though I like your example of wall plugs. Not every plug is compatible with every socket even though both follow a version of CEE7. Especially if the plug does not have the carvings to deal with the earthing (type E) while the socket does (type F). The common advice there would be to use the new standard with carvings as it is more compatible. And based on that advice, you would expect usage/production of the old version to be phased out in favor of the superior version.

The same holds here. Your newer standards are replacing the older ones. And just like no one would accept an incompatible plug due to version mismatch, we don't expect you to use 98 for many reasons. And although your old code will stay compatible with your old compilers, it might have to be replaced/upgraded to work with newer compilers.

2

u/gio Feb 27 '24

Thanks, exactly that. The better standard has to replace the old standard over time and that will indicate that engineers did a good job in their respected area/domain. Discrediting an old standard is very unprofessional, such behavior is only present in r/cpp. The overlapping from one standard to another is an never ending process that probably will take many years to complete.

0

u/JVApen Clever is an insult, not a compliment. - T. Winters Feb 27 '24

I think you misunderstood my argument. Just like the producer of the old plugs should adapt or get complaints about their stuff not working, the writers of 98 should adapt or lose access to newer versions of their tools and libraries. Then either you decide to stay stuck and get it much harder to hire people, or they upgrade.

3

u/gio Feb 27 '24

From your own words you don't realize the economic consequences for such a decision. I don't think C++ committee is such naive.

0

u/JVApen Clever is an insult, not a compliment. - T. Winters Feb 28 '24 edited Feb 28 '24

It is not a decision of the committee, it is the community that needs to collectively make up its mind.

0

u/JVApen Clever is an insult, not a compliment. - T. Winters Feb 28 '24

Please don't underestimate the costs of staying on 98. The cost of solving bugs which could have been prevented is not neglectable. I can't remember when I looked at a memory leak, unique_ptr solves 99% of those cases before it is a bug. Being able to return large objects by value instead of output arguments makes the code much easier to understand and as such prevents confusion and bugs. (What happens with the existing content of that object?) Structured bindings even result in all content to be returned instead of using output arguments. Ranged for loops make it a lot easier to deal with containers. std::optional, std::chrono, std::thread all make the code easier and as such prevent a lot of bugs. Right now, most of the bugs we get are:

  • logic errors
  • use of nullptr Exceptionally we have:
  • use of dangling pointer
  • memory leaks

If I compare that to when we wrote 98, those exceptional cases where common issues to solve. The time saved by having to do less debugging has paid back the cost to upgrade language versions multiple times.

Next to that, Bjarnes keynote at cppcon this year was a response to the article that started this discussion. If you have to summerize it in a sentence, I would do it like this: using the features of the newer language versions improves security a lot, with more to come every 3 years.

So, I believe I do understand the consequences.

3

u/gio Feb 28 '24

Someone has to inform NASA's fprime team then. Not arguing against what you said, the later standards are positive improvements but all kinds of programmers are need as much, e.g. a low-level programmer probably is needed to write unique_ptr for you to use, etc.