"C++ Must Become Safer" by Andrew Lilley Brinker
https://www.alilleybrinker.com/blog/cpp-must-become-safer/
"Not everything will be rewritten in Rust, so C++ must become safer, and
we should all care about C++ becoming safer."
"It has become increasingly apparent that not only do many programmers
see the benefits of memory safety, but policymakers do as well. The
concept of “memory safety” has gone from a technical term used in discussions by the builders and users of programming languages to a term known to Consumer Reports and the White House. The key contention is
that software weaknesses and vulnerabilities have important societal
impacts — software systems play critical roles in nearly every part of
our lives and society — and so making software more secure matters, and improving memory safety has been identified as a high-leverage means to
do so."
Not gonna happen since to do so would remove the purpose of C and C++.
Lynn
On 7/19/2024 6:40 AM, David Brown wrote:
That said, I think it will be good to see more safety-related features
added to C++, such as contracts and borrow checking. And more static
analysis to make it harder to write risky code is always a nice thing.
What is borrow checking ?
On 7/23/2024 3:48 AM, Paavo Helde wrote:
On 23.07.2024 04:38, Lynn McGuire wrote:
On 7/19/2024 6:40 AM, David Brown wrote:
That said, I think it will be good to see more safety-related
features added to C++, such as contracts and borrow checking. And
more static analysis to make it harder to write risky code is always
a nice thing.
What is borrow checking ?
Looks like built-in and default-used std::unique_ptr + std::move(), so
the Rust compiler can e.g. issue compile-time errors when a moved-away
variable is used.
For C++ the same is done by e.g. MSVC++ analyzer and other static
analysis tools:
#include <vector>
void foo(std::vector<int>&& v) {}
int main() {
std::vector<int> vv{ 1,2,3,4 };
foo(std::move(vv));
return vv.empty();
}
main.cpp(7): warning C26800: Use of a moved from object: ''vv''
(lifetime.1).
Plus in Rust it allegedly also helps with multithread locking, though I
was not able to figure it out in 10 minutes of googling.
Ah, my multithreading has not been good so far. I have three threads in
my main app and none of the variables involved cross the thread boundaries.
Am 23.07.2024 um 10:48 schrieb Paavo Helde:
For C++ the same is done by e.g. MSVC++ analyzer and other static
analysis tools:
#include <vector>
void foo(std::vector<int>&& v) {}
int main() {
std::vector<int> vv{ 1,2,3,4 };
foo(std::move(vv));
return vv.empty();
}
main.cpp(7): warning C26800: Use of a moved from object: ''vv''
(lifetime.1).
Plus in Rust it allegedly also helps with multithread locking,
though I was not able to figure it out in 10 minutes of googling.
C++ says that moved from objects are left in an indefinite state,
but for vectors this actually doesn't happen. With strings this
might happen due to the short string optimization so that there
might be a copy instead of a move.
On 23.07.2024 04:38, Lynn McGuire wrote:
On 7/19/2024 6:40 AM, David Brown wrote:
That said, I think it will be good to see more safety-related
features added to C++, such as contracts and borrow checking. And
more static analysis to make it harder to write risky code is always
a nice thing.
What is borrow checking ?
Looks like built-in and default-used std::unique_ptr + std::move(), so
the Rust compiler can e.g. issue compile-time errors when a moved-away variable is used.
For C++ the same is done by e.g. MSVC++ analyzer and other static
analysis tools:
#include <vector>
void foo(std::vector<int>&& v) {}
int main() {
std::vector<int> vv{ 1,2,3,4 };
foo(std::move(vv));
return vv.empty();
}
main.cpp(7): warning C26800: Use of a moved from object: ''vv''
(lifetime.1).
Plus in Rust it allegedly also helps with multithread locking, though I
was not able to figure it out in 10 minutes of googling.
And with modern C++, you can also automate lots of things and write</snip>
clearly memory-safe code, just as well as many managed languages. The difference is that with C++ you can /also/ write unsafe code with all
the risks available to more manual low-level programming. Resource management with smart pointers and standard containers can be as "memory safe" as code written in Python - but C++ also lets you use manual
malloc() and C-style arrays and pointers, with the risks these entail.
(Of course you can write correct memory-safe code in that style too.)
"C++ Must Become Safer" by Andrew Lilley Brinker
https://www.alilleybrinker.com/blog/cpp-must-become-safer/
"Not everything will be rewritten in Rust, so C++ must become safer, and
we should all care about C++ becoming safer."
"It has become increasingly apparent that not only do many programmers
see the benefits of memory safety, but policymakers do as well. The
concept of “memory safety” has gone from a technical term used in discussions by the builders and users of programming languages to a term known to Consumer Reports and the White House. The key contention is
that software weaknesses and vulnerabilities have important societal
impacts — software systems play critical roles in nearly every part of
our lives and society — and so making software more secure matters, and improving memory safety has been identified as a high-leverage means to
do so."
Not gonna happen since to do so would remove the purpose of C and C++.
Lynn
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 55:13:36 |
Calls: | 10,397 |
Calls today: | 5 |
Files: | 14,067 |
Messages: | 6,417,425 |
Posted today: | 1 |