Skip to content

CPP Common Knowledge notes!!

20-Nov-10
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
{
public:
virtual void foo();
};

class D1 : public virtual Base
{
public:
void foo2();
};

class D2 : public virtual Base
{
public:
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;
public:X()
{
buf = new char[100];
for(int i = 0;i<100;i++) 
modified = false;
if( < 98)
return;
buf[index] = c;
modified = true;
}

void printdata()
{
cout << "Data is "<<; 
ptr =static_cast(::operator new(sizeof(X)+100));// X::buf is not init!!
ptr->setData(0,'c');
}

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

class Hoo
{ 
char* buf; 
int size;
public: 
//copy CTor 
Hoo() 
{  
buf = 0x00;  
size = 0x00; 
}

 ~Hoo() 
{  
if(buf)  
{   
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)  
{   
if(buf)   
{    
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;
data.setData("Hello",5);
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.

Notes….

26-Aug-10
8/25/2010
---------
>>POM#1
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

>>POM#2
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.

>>POM#3
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.
max<double>(4,4.2)    
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

8/26/2010
---------
Task for today:
1. chk the tower of hanoi problem
2. chk two design patterns and make notes abt them

Mobical.net : Remote sync, worked for me!!!

06-Aug-10

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 mobilecal.net.

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.

10-Jul-10

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.

06-Jul-10

Here are the steps to debug Webkit in Linux using Eclipse. This has been reproduced here verbatim from
here
.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 buildspec.mk and rebuild webcore and xml2.
If you don’t have buildspec.mk under the root directory yet, please copy build/buildspec.mk.default to the root (android/)

DEBUG_MODULE_libwebcore:=true 
DEBUG_MODULE_libxml2:=true 
TARGET_CUSTOM_DEBUG_CFLAGS:=-O0 -mlong-calls 

Add

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

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

Use

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/BoardConfig.mk, 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 
Continuing. 

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

android/out/target/product/dream/symbols/system/bin/app_process

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

android/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb

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

android/out/target/product/dream/symbols/system/lib.

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
[/cpp]
“adb forward tcp:5039 tcp:5039”.
[/cpp]
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:

./prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb

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 (com.android.Browser)
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!!

22-Jun-10

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.

18-Jun-10

Some links giving resume writing tips:

Game engines resources update.

19-May-10

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

05-May-10

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.

04-May-10

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.