Obscure C++ Features [from the newsletter]
-
Most of these "obscure" feature will not pass code review.
Nihil obstat
-
Most of these "obscure" feature will not pass code review.
Nihil obstat
Thank elephant for that! Use most of those, and you deserve to be shot...
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
Most of these "obscure" feature will not pass code review.
Nihil obstat
-
-
I don't know, it take some balls to tell someone their code sucks. Except for Griff, that's a given.
Reality is an illusion caused by a lack of alcohol
-
I don't know, it take some balls to tell someone their code sucks. Except for Griff, that's a given.
Reality is an illusion caused by a lack of alcohol
OI! I don't suck balls!
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
OI! I don't suck balls!
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
Your code however...
Reality is an illusion caused by a lack of alcohol
-
Your code however...
Reality is an illusion caused by a lack of alcohol
Oh, that? It suckzorz donkey balls. :laugh:
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
Thank elephant for that! Use most of those, and you deserve to be shot...
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
That might be so, but I think their program still would execute, and not the person :sigh:
-
I will confess to having used two of those practices, but I washed my hands afterwards.
Software Zen:
delete this;
-
I remember the redefinition of keywords: a friend of mine has some headers that let him compile and run simple Pascal programs using C.
-
Most of these(except templates tricks etc.) has nothing to do with C++, but are inherited C constructions. And some of them are quite useful in system programing.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
-
I was quite delighted to discover among the alternate operator tokens keywords for &&, || and !. I never really liked these "rude" logical operators and this gave me a sufficient incentive to switch to the nicer litteral representation. Isn't that beautiful ?
if (i < N and not Odd(A[i]))
I will not embrace the tokens for &, | and ~, as these correspond to bitwise operators which are more arithmetic in essence and compare to the usual +, -, *, /. Even less the _eq forms, which in my opinion are misnomers: f.i. or_eq should read bitor_eq.
-
Obscure, you say? How about ... The comma operator; result = a , b; computes a, discards it, computes b, and assigns b to result. C++ (and C)'s hidden operator language; Conditional operator result = a ? b : c; evaluates a, then evaluates b if a is nonzero, or else evaluates c. The comma operator above as a way to do sequences as an expression. All C++ is missing is a value-returning loop. I do second the motion for method pointers as the most obscure and underused (but useful) aspect of C++. Or maybe virtual multiple inheritance, which can get mind-bendingly complex in examples I've seen in the wild.
-
I remember the redefinition of keywords: a friend of mine has some headers that let him compile and run simple Pascal programs using C.
I remember this one from a C++ course I took:
#define ;; ever;
Which of course allowed infinite for loops to be coded as
for(ever) {...}
-
I remember this one from a C++ course I took:
#define ;; ever;
Which of course allowed infinite for loops to be coded as
for(ever) {...}
-
I've tried my hand at redefining the comma operator[^] after I've seen it in Blitz++ and Boost::Spirit (!). But I eventually discarded the idea due to various problems. I tried metaprogramming (the factorial implementation), but only for instructional purposes, not for real use. What I actually use in real code: 1. I do overload ++ and -- (pre and postfix both) a lot. 2. I did use in-place new and explicit call of destructor for the implementation of a memory pool. I don't see anything wrong with that as there really is no other good way to allocate memory for C++ objects and ensure proper initialization. (and cleaning up after release, without freeing the memory) 3. I do use static methods occasionally. But I wonder why they are on the "obscure features list" to start with. Of the remaining features listed in that article, I would indeed consider them obscure as I either wasn't aware them, or never found a useful application. ;) Passing a function as a template parameter is the only feature of these that I would consider useful, although I haven't actually used it myself. If you want an equally or more obscure feature, the only thing I can think of from the top of my head are trigraphs. (see http://www.gotw.ca/gotw/086.htm[^] - it also contains examples for some items already on the list)
-
I've tried my hand at redefining the comma operator[^] after I've seen it in Blitz++ and Boost::Spirit (!). But I eventually discarded the idea due to various problems. I tried metaprogramming (the factorial implementation), but only for instructional purposes, not for real use. What I actually use in real code: 1. I do overload ++ and -- (pre and postfix both) a lot. 2. I did use in-place new and explicit call of destructor for the implementation of a memory pool. I don't see anything wrong with that as there really is no other good way to allocate memory for C++ objects and ensure proper initialization. (and cleaning up after release, without freeing the memory) 3. I do use static methods occasionally. But I wonder why they are on the "obscure features list" to start with. Of the remaining features listed in that article, I would indeed consider them obscure as I either wasn't aware them, or never found a useful application. ;) Passing a function as a template parameter is the only feature of these that I would consider useful, although I haven't actually used it myself. If you want an equally or more obscure feature, the only thing I can think of from the top of my head are trigraphs. (see http://www.gotw.ca/gotw/086.htm[^] - it also contains examples for some items already on the list)