

Obscure C++ Features - burke_holland
http://madebyevan.com/obscure-cpp-features/

======
olliej
The behavior of [] is from C -- it's not a bizarro C++ feature.

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 )

~~~
dljsjr
Definitions of obscure:

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).

~~~
bcoates
It's not an opinion, it's forbidden by the language specification so it's not
portable.

------
bnegreve
_C++ contains a syntactical shorthand for simultaneously declaring a variable
and branching on its value._

    
    
        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.

~~~
ben0x539
The noteworthy bit is that declarations are valid in the conditional
"expression" of if-statements and evaluate to the declared variable. It's imo
not obvious that declarations are expressions sometimes.

~~~
Sharlin
To be precise, declarations are never expressions - there are two forms of if
and while statements in the grammar, one taking an expression and the other a
declaration.

------
alexchamberlain
Are these really obscure? I've used most of them.

~~~
vinkelhake
I was going to say the same thing. I guess I've been doing C++ for too long to
consider these obscure. Any nontrivial C++ codebase is likely to have several
of these.

------
wereHamster
"Alternate operator tokens" - there are more tokens you can use instead of
[]{} etc. See <http://en.wikipedia.org/wiki/Digraphs_and_trigraphs>

------
ben0x539
My favorite is that these are indeed "alternate operator _tokens_ " an so you
can use `compl` in place of ~ to name a destructor. Like, for explicit
destruction:

    
    
        MyType* foo = ...;
        foo->compl MyType();

~~~
duskwuff
If there is ever an IOC++CC (International Obfuscated C++ Code Contest), I
imagine that this technique will show up all over the place.

Bonus: Can you paste together the "compl" token with preprocessor macros?

------
usefulcat
Re. the "redefining keywords" trick. I know this works with at least some
versions of g++. However when I tried doing it in MSVC 2008 I ended up with
link errors between the library object files (compiled without the
redefinition trick) and the app executable that did use the trick. It looked
like MSVC was encoding the visibility in the mangled method names.

~~~
atesti
The first review I read about the StarOffice source code (now OpenOffice,
LibreOffice) back then when it was open sourced was that it was full of
#define private public lines

------
asveikau
I think the only thing "obscure" in this list is the "pointer-to-member"
syntax. It's conceptually simple but the syntax is pretty bizarre, hard to
remember even when you're searching for it, and probably a lot of C++
programmers working professionally will not recognize it.

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.

------
wereHamster
Dark font on dark background. Unreadable.

~~~
alexchamberlain
There are some advantages to the company firewall blocking style sheets.

~~~
laumars
Sorry, I know I'm drifting massively off topic now, but why on earth would any
company adopt such a policy? It's not even as if CSS files can carry
executable code (sure, they can reference such content, but then block that
stuff instead of the style sheets themselves).

~~~
geon
Discourage browsing?

------
PySlice
Perl eats C++'s "most vexing parse" for breakfast.

------
erlkonig
Although the article's interesting (hardly new info, but concisely described),
the ghetto antialiasing, - or whatever excuse the CSS-writer had in mind for
gray-on-gray text - really hurts legibility. Seriously, high contrast is the
answer - look at 95%+ of all books (white on black is high contrast but costs
a lot more in ink, so books only typically have white on black).

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.

------
hamidr
Obscure? You may think so but sometimes these things buy you lots of time.

~~~
gensym
Yes. Time in a rubber room.

------
rhapsodyv
Here: <http://www.cppgm.org> I'm learning a lot of this features!

------
kyberias
Dark gray text on black background. Really?

------
coolwanglu
Oh I just love C++ better!

------
pasquinelli
i didn't find any of these things obscure. that tells me that the road to
recovery for ex-c++ programmers is a long one. one day at a time.

