C++ Programming - Empty Base Class Optimization

It is know that a class without any non-static data members will be having a size of 1 byte.

class A {
static int i;
}; // sizeof(A) will be 1


Now suppose that we inherited this to create another empty (no non-static member) class B, as follow


class B: public A {

}; // Still sizeof(B) will be 1 instead of 2 bytes


Now lets take the case in which the inherited class has a non-static data member.

class C: public C {
int element;
}; // This time sizeof(C) will be 4

This time instead of 4 + 1 = 5 bytes it gave 4 bytes, this was because of the base class optimization.

Note: I will be refering sizeof(int) as 4bytes

Labels: ,

Posted by - at 6:54 am | 1 comments read on

Programming - Code Browsing Made Easy Using ctags+gvim

Using ctags+gvim for code browsing...


The following command generates a tag file for C/C++ ONLY, you can extend the exclude list for more specific one.

ctags -R --languages="-Java,-JavaScript,-HTML,-Perl,-Sh" < directory name >

For listing all supported languages use

ctags --list-languages

Labels: , ,

Posted by - at 6:51 am | 0 comments read on

Archives

  • May 2011
  • February 2009
  • December 2008
  • November 2008
  • October 2008
  • August 2008
  • April 2008
  • December 2007
  • November 2007
  • January 2007
  • December 2006
  • October 2006
  • September 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005

Links