Obscure C++ Features
madebyevan.com
madebyevan.com
The "redefining keywords" is the pre-processor. That's what it does. There isn't anything magic here. Strictly speaking it can be run entirely ahead of the C/C++ compiler, on any file you want. There's no requirement that it is C/C++ - you could use it on a python script (as long as you weren't using # comments anywhere :D )
1. Not easily distinguished
2. Not readily understandable/expressable
3. Not commonly known
I didn't see the author use the word "bizarro" anywhere, nor make any claims about any of this stuff being weird. He actually presented almost everything in a fairly neutral tone, except when he said that using the preprocessor to override keywords was dangerous (which could be construed as opinion).
I'd say that a feature of C++ is still a feature of C++ even if the same feature is in C.
For example, I could do:
class MyClass {int operator+(int a) { return a; }};
MyClass x;
x + 1; // Valid.
1 + x; // Type error.
EDIT: My mistake. C++ requires these operators to be nonstatic member functions: = -> [] ()
Which, annoyingly enough, means that you can define '+' over types that you haven't implemented, but you can't define [] or =. if (MouseEvent *mouse = dynamic_cast<MouseEvent *>(event))
I think it is a complicated description and a complicated example for saying that the assignment operator (=) returns the value that was assigned. if (mouse = dynamic_cast<MouseEvent *>(event))
then it would indeed just be an if condition expression that happened to be an assignment.But the variable is being declared as well, so what's actually going on here is a declaration and an initialiser expression. There is actually new functionality here that needed a bit of language design thought, e.g., the declared variable's scope is the whole if statement, not just the condition expression.
for (int i = 0; i < len; ++i) { }If, for example, you'd like to reverse the condition, you can't write
if (!(MouseEvent *mouse = dynamic_cast<MouseEvent *>(event)))
{}
because a definition is not a general expression, but was only added as an "extra" to allow its use in some cases in conditionals. MouseEvent *mouse;
if(mouse = dynamic_cast<MouseEvent *>(event)))
but it is not the same thing. MyType* foo = ...;
foo->compl MyType();Bonus: Can you paste together the "compl" token with preprocessor macros?
I remember a few years ago I was writing some code where using pointer-to-struct-member made lots of sense to me. Doing a code review I was asked politely by a peer to rewrite without them. I disagreed but didn't mind doing so, if it made people on the team happier about readability.
Alas, this site is not an exception. Many websites sacrifice readability to some graphic designers' whim.
Back to the content, C++ syntax has always been a bit nasty, and the try/catch for constructor initializers adds yet another wart. It makes me miss LISP again.