cplusplus.co.il

Archive for the ‘tricks’ Category

Quines

Posted by: rmn on: 16/04/2010

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.

Escaping overloaded operators

Posted by: rmn on: 19/02/2010

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 by: rmn on: 28/12/2009

Are you familiar with the new, all-mighty, arrow “–>” operator in C++ ?

Measuring the size of a type without sizeof

Posted by: rmn on: 25/11/2009

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 by: rmn on: 29/10/2009

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 by: rmn on: 14/08/2009

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?


Follow

Get every new post delivered to your Inbox.

Join 25 other followers