Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Writing clear, concise, and efficient code in C++ has never been simpler or easier. The improvements in C++ over the last 15 years have been qualitative.

So many complex, esoteric, and difficult to maintain incantations that used to be required for efficient code generation are no longer necessary.

 help



How do you process read-only mmaped data in C++, in accordance with the language rules? As an example.

That was addressed circa C++17 IIRC, same with all of the technically UB surrounding DMA memory. You needed non-obvious incantations for some use cases but they were expressible. C++23 eliminated most of those incantations. Before all of this you had to use “blessed” incantations that were technically UB but which compilers needed to allow because the code was expressing a valid use case.

I find it crazy that popular systems languages didn’t have an explicitly valid way to deal with all of these ambiguous ownership and lifetime issues around memory until relatively recently.


Can you give some specifics? I feel like this is adjacent to my work and I'm not sure what you're referring to which makes me feel I've missed something important.

Not OP but I believe this is referring to defining a `volatile const` for a read only register which C++ does not allow because you would need to initialize a const. Not sure what the C++17 solution would be

I think there are lots of Unix APIs that are impossible to use without UB, e.g. SCM_RIGHTS (maybe io_uring as well?).

Implementations are free to define UB.

UNIX APIs are not implementations.

You compile programs for Unix using language implementations.

C++ implementations don't make any sort of special or unique accommodations for UNIX/POSIX APIs. For the most part calls into external libraries are firewalled and not optimized in a way that typically engenders undefined behavior, so POSIX APIs tend to work. But any external library would also work since it's not like POSIX is exclusively shielded or singled out in any particular way.

If a compiler for Linux time travels whenever you use SCM_RIGHTS, take it back for a refund - it's faulty.

You can try to request a refund for free software but the terms of the compiler explicitly state that undefined behavior is permitted to "time travel" and that there's nothing faulty about it. That's C++ for you ;P

That's not something that's unique to C++ though. For example, Rust has the same issue.



Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: