Skip to content

CPP Common Knowledge notes!!

class TestCode
//This is a test for Syntax highlighter!!!

Item #11 : Compiler puts stuff in classes.
Compiler puts a virtual function table ptr in each class object with virtual functions.
Virtual function table pointer not same across platforms!!
Compiler may not put all these extra constructs in a struct.
Virtual inheritance is required when the diamond inheritance is causing issues.
For example:

class Base
virtual void foo();

class D1 : public virtual Base
void foo2();

class D2 : public virtual Base
void foo3();

class SD : public D1, public D2
// We have taken care of the diamond inheritance issue with the virtual keyword
// so compiler is gonna shut up now!!

Item #12 : Assignment & initialization are different.
These two ops not so diff in built-in types like int, char etc.
For user-defined types, it would not be advisable to perform user-defined assignment.

class X
char* buf;
mutable bool modified;
Y obj;
buf = new char[100];
for(int i = 0;i<100;i++) 
modified = false;
if( < 98)
buf[index] = c;
modified = true;

void printdata()
cout << "Data is "<<; 
ptr =static_cast(::operator new(sizeof(X)+100));// X::buf is not init!!

Item #13 : Copy operations.
Copy construction and copy assignment are different operations.

class Hoo
char* buf; 
int size;
//copy CTor 
buf = 0x00;  
size = 0x00; 

delete[] buf;   
buf = NULL;  
size = 0x00; 

 void setData(char* data, int asize) 
size = asize;  
buf = new char[size + 1];  
memset(buf, 0x00, size+1);  
strncpy(buf, data, size); 

 Hoo(Hoo const &amp; hoo) 
 setData(hoo.getBuf(), hoo.getSize()); 

 Hoo& operator= (Hoo const &hoo) 
if(this != &hoo)  
delete[] buf;    
buf = NULL;   
size = 0x00;   
setData(hoo.getBuf(), hoo.getSize());  
return *this; 

 char* getBuf() const 
return buf;

 int getSize() const { return size;}


void copy_ctor_assgn()
Hoo data;
Hoo dat2(data);
//copy ctor invoked here
Hoo dat3;
dat3 = dat2;// assgn operator invoked here

Item #14 :Function Pointers.
Legal to point to inline functions, but the resultant call will not be inline.The compiler will not be able to determine at compile time what function is being called.
Can also point to an overloaded function. The particular function called will depend on the match between the function ptr type and the overloaded functions.


Read 10 pages of Modern C++ design.
Realised that it needs more knowledge about templates.
Started with reading the book : C++ Templates, The Complete Guide 2002.chm

Function templates
function template syntax:
template <typename a1,....>
funnction declaration or definition using T
'typename' introduces type parameter
historical alternative to typename is 'class'.
templates are generated once for each type for which it is used
process of replacing template types with concrete types is called instantiation.
use of function template triggers the 'instatiation'.
templates are compiled twice:
1. once for checking the syntax of the template.
2. second time to check the operations mentioned are valid for 
the type used for template instantiation.

template parameters are determined by the arguments passed at the call time.
no automatic type conversion is allowed.

Function templates have two kinds of parameters
1. template params - declared in angle brackets, N no. of them can be declared,
 no default template arguments can be specified.
e.g.: template <typename T> // T is template param
2. call params - declared in parenthese after function template name
foo(T p1, T p2) //p1,p2 are call params
call params deduced from template params, so they are related.
function template argument deduction
when template return type cannot be deduced from template and 
call params then needs to be explicitly mentioned.
template argument deduction does not try to determine the return type
another method to just declare one type and then let the compiler deduce the rest.
template <typename RT, typename T1, typename T2> 
inline RT max (T1 const& a, T2 const& b); 
// OK: return type is double, T1 is deduced as int and T2 is deduced as double.
overloading function templates->overloading resolution revisited
not part of every function call
-- calls to functions thru function ptrs 
-- calls to member functions thru ptr to member functions
not subjected to resolution as they are determined at runtime.

function like macros cannot be overloaded and hence not subjected to reso

Task for today:
1. chk the tower of hanoi problem
2. chk two design patterns and make notes abt them : Remote sync, worked for me!!!


I just moved to SE P1i from N91. The moving was a bit tricky for me. As I was moving for the first time to a Non-Nokia device. I tried moving my contacts and events using Oxygen phone manager and Mobiledit! , but both did not work for me. Ovi was not an option due to the Nokia only support. So after a bit of search I found

I was able to move the contacts within 15 mins of finding the website and setting up an account. I would really rate that as fast. Well I could not move my messages, but I can live with that, as the 200+ contacts were moved quite easily.

I would strongly recommend it ,especially if you are the frequently shifting from one device to another.

Data structures to Algorithm analysis to discrete mathematics & calculus.


I started reading “Data Structures & Algorithms with Object-oriented Design patterns in C++” only to realize that I was totally lost in the mathematics. Maths has been greek to me and I have been avoiding it as much as possible. To put it simply, am bad at numbers. So now to understand the algorithm analysis part along with the O notation I need to first quickly grasp Discrete mathematics and some calculus as well.

I will update again once am done with Discrete mathematics,so Grimaldi here I come.

Steps to debug Webkit using Eclipse.


Here are the steps to debug Webkit in Linux using Eclipse. This has been reproduced here verbatim from
.I am currently verifying these steps.

Debug Native C++ Code:
To get meaningful debug info, you do need to build WebCore with -O0. It is simple. Add the following to your and rebuild webcore and xml2.
If you don’t have under the root directory yet, please copy build/ to the root (android/)



"ADDITIONAL_BUILD_PROPERTIES += debug.db.uid=100000"

so that it will wait for you to connect gdb when crashed.


rm out/target/product/dream/system/build.prop

to make sure it takes effect.
To rebuild webcore and xml2:

make clean-libwebcore clean-libxml2 && make <br>

Note: If you get system image is too large, you can manually change vendor/htc/dream/, and set BOARD_SYSTEMIMAGE_MAX_SIZE to a bigger number, e.g., 94371840
(sapphire’s cap).
Debugging native code on emulator is much better now.
Start emulator and activate browser.
In a different shell, do

"gdbclient app_process :5039 browser" 

It should connect to emulator now, and you should see following
(the first three lines) in gdb. Type “c” for continue.

__futex_wait () at system/bionic/arch-arm/bionic/atomics_arm.S:121 
121         ldmia   sp!, {r4, r7} 
Current language:  auto; currently asm 
(gdb) c 

If you want to use Eclipse, it will be easier if you have Eclipse 3.3 instead of 3.2 (on Mac). Here is how to set up debug configuration.

Run -> Debug…, select C/C++ Local Application, then click New. Give a name to your configuration, like release_native, select android project, and


for the application.
In Debugger tab, select GDB Server for the debugger.
Under Debugger Options choose Main tab first, enter


as GDB debugger.
Choose TCP for connection and use 5039 as port.
Then under Shared Libraries, add


Davidc: Not sure if the is the same for everyone, but I had to reduce the length of the paths to avoid GDB timing out. To do this, remove the paths set in the Source tab, and add the path to
the files you are debugging.
To debug an application with Eclipse, you need to gdbserver on the target (emulator or hw) and forward the port.
In a shell, do
“adb forward tcp:5039 tcp:5039”.
In the shell, do

"adb shell gdbserver :5039 --attach `pid browser`".

Start the debugger in Eclipse
If you have trouble to use Eclipse to debug native on Linux, you can use gdb. To use gdb, you need to create a ~/.gdbinit with following content:

file ./out/target/product/dream/symbols/system/bin/app_process 
set solib-search-path ./out/target/product/dream/symbols/system/lib 
target remote localhost:5039 

It does exact the same thing as Eclipse setup. Then you can start gdb from android/ directory:


To debug native code before the browser has fully started:
Open DevTools application, select Development Settings.Select Debug App at the top, and pick the browser from the list (
Click ‘Wait for debugger’
Go back to home and launch the browser
Follow from step #2 in the steps described above under “Debugging native code on emulator is much better now.”
At this point, GDB is attached but the browser is still waiting for the Java debugger
Attach the Java debugger and the browser will automatically continue.

07th July : Update : We are getting an error with system/bin/linker.Need to fix it to load the symbols properly.

Hello Android!!


Today I created the customary ‘HelloWorld’ program in Android SDK using the eclipse IDE.
Well the documentation is exhaustive and helpful. The presence of many online sources/forums is also quite encouraging.

The main site to check is the Android Developer Site.

Resume writing tips.


Some links giving resume writing tips:

Game engines resources update.


Found one useful link related to graphics acceleration in Symbian devices.
Just to my surprise came to know that Nokia 6630 was the first device to have 3D API’s. That is one more first apart from the megapixel camera it sports.

Also got one more link which details the CPU information of the leading smartphones.
Apart from the core the iPhone is a beast in terms of RAM. So comparison with low resourced Symbian devices is a bit unfair.

Getting organized – Update I


While yesterday I had decided to name the application TaskWerks, today I thought LifeWerks would sound better. So the finalised name is LifeWerks

I have started creating the requirements and wireframes of the screens as well.
Will post the final document and wireframes once completed.

Getting organized.


I have been too much unorganized for too long now. This has left me wasting such important time without achieving anything till now. So am moving on to leading a more organized and planned lifestyle. LifeHacker has some great tips and am gonna use them.
So am making a Symbian application which will be useful in planning things and am gonna call it TaskWerks.

Task for tomorrow : Post more details about the TaskWerks.

?php echo( date(