News for hackers. Stuff that matters.
Re:A Usable C++ Dialect That Is Safe Against Memory Corruption by saagarjha on Thursday March 15, 2018 @03:14PM (#16595712)
Mostly agree, but:

> Don't use C API. The STL should provide you with enough API to use the proper C++ types, either std::string or std::string_view in C++17 if possible.

Sometimes you're working with C API that gives you back a char * that they've already allocated. AFAIK there isn't a way to create an std::string out of that without a copy.

> you can't static_cast<> a pointer

You can static_cast a void * into other kinds of pointers.

> use std::array

Do you mean std::vector and at()?

Re:A Usable C++ Dialect That Is Safe Against Memory Corruption by scott_s on Thursday March 15, 2018 @04:41PM (#16596360)
> Do you mean std::vector and at()?

No, std::array was added in C++11: http://en.cppreference.com/w/cpp/container/array

Re:A Usable C++ Dialect That Is Safe Against Memory Corruption by saagarjha on Thursday March 15, 2018 @11:28PM (#16598374)
std::array has its size fixed at compile time, so there's no reason for you to do have to do bounds checking…
Re:A Usable C++ Dialect That Is Safe Against Memory Corruption by blub on Friday March 16, 2018 @03:20AM (#16599140)
char buffer[100] also has a fixed size and is responsible for most buffer overflow bugs :)

array::at is just as mandatory as vector::at IMO.

Re:A Usable C++ Dialect That Is Safe Against Memory Corruption by nobugs on Friday March 16, 2018 @01:12AM (#16598786)
> You can static_cast a void * into other kinds of pointers.

Moreover, you can use static_cast for downcasts (from the parent class to child class) - without runtime costs of dynamic_cast. static_cast is not safe (it doesn't perform runtime checks), but reinterpret_cast is even worse (it doesn't perform even compile-time checks).

Re:A Usable C++ Dialect That Is Safe Against Memory Corruption by fooker on Thursday March 15, 2018 @04:22PM (#16596220)
>AFAIK there isn't a way to create an std::string out of that without a copy.

You can use std::string_view, Google's StringPiece or llvm::StringRef.