6 ms·
Obscure C++ Features
- ben0x539 14y agoMy 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 14y agoIf 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?
- wereHamster 14y agoDark font on dark background. Unreadable.
- alexchamberlain 14y agoThere are some advantages to the company firewall blocking style sheets.
- laumars 14y agoSorry, 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 14y agoDiscourage browsing?
- papsosouid 14y agoDon't the mainstream browsers support custom styling yet? Like say, a high contrast style?
- ycombobreaker 14y agoIn Opera, "Page > Style > User Mode" does the trick. I know FF and IE have similar functionality, but I don't know the shortcut.
- colanderman 14y ago"Page > Style > High Contrast" will get you high contrast while preserving layout.
- papsosouid 14y agoYeah, opera is why I said mainstream. I haven't used anything other than opera in so long that I don't really know which features firefox and chrome still haven't copied yet.
- Luyt 14y agoIndeed. In Firefox I do View -> Page Style -> No Style. Alas, this site is not an exception. Many websites sacrifice readability to some graphic designers' whim.
- alexchamberlain 14y agoAre these really obscure? I've used most of them.
- vinkelhake 14y agoI 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.
- nawitus 14y agoObscureness is subjective. In my opinion this article would be worse if 50% of the least obscure features were not presented.
- scott_s 14y agoThat's what I thought, but then that last one... I had no idea.
- wereHamster 14y ago"Alternate operator tokens" - there are more tokens you can use instead of []{} etc. See http://en.wikipedia.org/wiki/Digraphs_and_trigraphs http://en.wikipedia.org/wiki/Digraphs_and_trigraphs
- rhapsodyv 14y agoHere: http://www.cppgm.org http://www.cppgm.org I'm learning a lot of this features!
- olliej 14y agoThe 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 14y agoDefinitions 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 14y agoIt's not an opinion, it's forbidden by the language specification so it's not portable.
- pubby 14y agoThere is somewhat of a requirement with the preprocessor - if you redefine a keyword and then include a standard library header it's considered undefined behavior. Maybe that's what the author meant.
- nawitus 14y ago>The behavior of [] is from C -- it's not a bizarro C++ feature. I'd say that a feature of C++ is still a feature of C++ even if the same feature is in C.
- _pmf_ 14y agoThe point was probably that it is not obscure; it's what you had to learn when using plain C in the first week.
- hamidr 14y agoObscure? You may think so but sometimes these things buy you lots of time.
- gensym 14y agoYes. Time in a rubber room.
- usefulcat 14y agoRe. 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.
- klodolph 14y agoIf I remember correctly, it's undefined behavior if you redefine keywords anywhere, not just for library headers as the article suggests.
- atesti 14y agoThe 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
- bnegreve 14y agoC++ 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.
- jomar 14y agoIf this were just 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.
- kelnos 14y agoI see this as no different than being able to do for (int i = 0; i < len; ++i) { }
- axusgrad 14y agoImagine my surprise, getting out of college and trying to use this at my job, when the compiler told me it was invalid! It wasn't obscure to me, but apparently was to the Sun Studio C++ compiler.
- 14y ago
- asveikau 14y agoI 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.
- eswangren 14y agoNone of these things are obscure. At all. It was an immediate fail to begin with an explanation of indexing as pointer arithmetic. This is known to any C or C++ programmer beyond an absolute beginner level.
- coolwanglu 14y agoOh I just love C++ better!
- pasquinelli 14y agoi 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.
- PySlice 14y agoPerl eats C++'s "most vexing parse" for breakfast.
- kyberias 14y agoDark gray text on black background. Really?
- erlkonig 14y agoAlthough 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.