Tag Archives: cpp

C++17 finalized

The C++17 specification has been finalized. The actual specification is under a paywall (wtf), but you can get the final draft of the pdf here. But it’s 1448 pages long and you most likely don’t have time to go over everything.

However, there’s this nice writeup that summarizes the new features in C++17. There are no new groundbreaking features, but some handy additions you might wanna use.

One of the first things that caught my eye is std::optional. I love optionals in Swift. They let you wrap values which might or might not be null and reduces the chances of null pointer exceptions. std::optional is a bit more awkward to use than Swift’s built-in optionals, but I hope people would start using them.

There’s also nested namespaces and structured bindings which will help with brevity and readability. Structured bindings are similar to destructuring in JavaScript.

How can you tell the type of a void pointer?

TLDR: You can’t

There’s a writeup on a newly found vulnerability in Adobe Acrobat Readers:

We all know that void pointers are by definition typeless, may point to any object, and any object may be cast to it. But surely, after we’ve cast an object pointer to a void pointer, it’s still possible somehow to detect its origin type, right? Not quite.

Once an object is cast to a void pointer, it’s absolutely impossible to detect its origin type. So, how do we check the type of a void*? The answer is that we don’t. And when you try, what you get is a vulnerability.

In case you’re not familiar with void pointers in C/C++, you can assign _any_ pointer to a void pointer, regardless of the type.

void *ptr = any_ptr;

This can be helpful if you don’t know what kind of a pointer you will receive in a function, etc. But usually it’s better to avoid them like the plague.