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.
Archive for the ‘tricks’ Category
Quines
Posted in tricks on 16/04/2010 | 5 Comments »
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 [...]
The omnipotent arrow operator
Posted in tricks on 28/12/2009 | 2 Comments »
Are you familiar with the new, all-mighty, arrow “–>” operator in C++ ? #include <iostream> int main () { unsigned count = 30; while (count –> 0) // count goes to zero std::cout << count << std::endl; }
Measuring the size of a type without sizeof
Posted in tricks on 25/11/2009 | 1 Comment »
Suppose you wanted to check the size (in bytes) of a certain type, WITHOUT using the sizeof() operator. How would you do that? And what is the size of an empty struct (or class), anyway?
Checking sizeof or the offset of a member
Posted in tricks on 29/10/2009 | 8 Comments »
Suppose we wanted to check the sizeof or the offset of a certain member within our struct (or class), without actually having an instantiated object to run the needed operations on. How would you do that?
Changing the vtable pointer
Posted in tricks on 14/08/2009 | Leave a Comment »
Most compilers implement dynamic binding by using a vtable whose pointer resides at the beginning of each object’s memory footprint (something along the lines of [vtable-pointer|..members..], if we are not considering virtual inheritance). Keeping this idea in mind, why don’t we go ahead and attempt to change that vtable pointer?