Feeds:
Posts
Comments

Archive for the ‘tricks’ Category

Quines

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.

Read Full Post »

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 [...]

Read Full Post »

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; }

Read Full Post »

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?

Read Full Post »

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?

Read Full Post »

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?

Read Full Post »