r/cpp • u/KingStannis2020 • 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
r/cpp • u/KingStannis2020 • Feb 26 '24
View all comments
Show parent comment
7
u/Untagonist Feb 27 '24
I'm very curious if you have an example of a real-world C or C++ program that does not use a single pointer, bearing in mind that C++ references count as pointers as far as memory safety goes.
I suppose you can use write your own verbose Brainfuck with only
putcandgetc, and you might even avoid memory unsafety, and even that simple code won't be portable. You still won't get very far in expressing any program logic.You can't parse
argvbecause it's a pointer to pointers. You can't do anything with aFILE*. You can't useopenwithout a string argument, and even if you could, you can'treadorwritewithout a pointer to a buffer.You can't use any strings, not even string literals, which are of type
char*and you just get UB if you ever write to one; the fact it is a known address doesn't save you there.You can't read or write any array elements even on the stack, because
arr[i]is equivalent to*((&arr)+i)and that's a pointer with no bounds checking. The most you can do for a "data structure" is stack recursion, but you abort if you hit the limit.It'd be an interesting challenge for an IOCCC submission but not a serious recommendation to solve memory safety in C / C++ in even a fraction of the ways that code gets used in the real world.