The C-Preprocessor is a very powerful mechanism, which offers many different features. One of these features is called Variadic macros: macros that accept a varying number of arguments. It is interesting to note at this point, that such Variadic macros, despite being part of the C99 Standard, are not part of the C++ Standard at [...]
Archive for the ‘cpp’ Category
Variadic macro to count number of arguments
Posted in techniques on 17/07/2010 | 10 Comments »
Futures: asynchronous invocation
Posted in concurrency on 31/05/2010 | 3 Comments »
In the concurrent world, a Future object refers to an object whose actual value is to be computed in the future. You can think of it as a handle to an asynchronous invocation of a computation that yields a value. Many so called concurrent programming languages support this idea as a native construct offered by [...]
Quines
Posted in tricks on 16/04/2010 | 5 Comments »
A Quine is a computer program which prints a copy of its own source code as its only output. Thus it is theoretically possible to compile such a program, run it, and then have its output compiled again to produce the initial program – in an infinite loop, forever.
Catching uncaught exceptions within terminate
Posted in mechanisms on 21/03/2010 | 1 Comment »
The handler std::terminate() is called whenever the exception handling mechanism cannot find a suitable catch clause for a thrown exception (and in some other cases. For example, when an exception is thrown during the handling of another exception – see this GotW post about std::uncaught_exception). It is possible to define a custom handler by using [...]
Escaping overloaded operators
Posted in tricks on 19/02/2010 | 6 Comments »
The possibility of overloading just about any C++ operator and having it do something entirely different from what it was designed for, can sometimes make life pretty hard. Here are a couple of examples: What if you wanted to take the address of an object, which had implemented an entirely different semantic for the ampersand [...]