Thursday, August 26, 2010

Compiling cpp with gcc

Hi,
I know the title is a bit confusing. But believe me, i am not trying to confuse :).
In very layman terms , g++ is nothing but a special version of gcc.
Ignoring all the complexities, the most trivial work it does is making cpp the default
language, which results in stdcpp library to get linked by default.

So, if you want to play a trick and compile your cpp code with gcc, just link the stdc++ lib by yourself.

$ gcc file1.cpp -lstdc++ -o output

This will do the trick.
Have tested it with basic helloworld, so if your complex template containing code doesn't compile with this, don't complain, more over you should give a thought about what template is actually doing to your code :).

Tuesday, August 24, 2010

The Old "new"

Remember the good old C days,
When after memory allocating code,
We had to check the pointer against NULL, just to make sure that the memory has actually been allocated.

int * arr = (int*)malloc(sizeof(int)*10);
if(arr==NULL)
{
// No memory allocated
}

Many people carry this habit from C to C++, which is not all together right.
As in CPP new operator throws an error, "bad_alloc" to be precise , in the case where memory was not allocated.

But if u like living in old days, and insist on comparing the pointer to NULL to check whether memory has been allocated or not. You can use

A * a = new(nothrow) A();

Now you can keep on reliving those times.

On a more serious note, this practise is not recommended in C++, but in some projects developed before C++ introduced "exception handling", this practise has to be continued.

Saturday, August 21, 2010

Dual booting on my phone

Hi Guys,
Finally i was able to install NITDroid android port to N900.
Been trying for over 2 months now, the problem was with my SD card.

Anybody wanting to try it out ( and having a N900 is a must :) ), can go to the link given below.

But having a wifi connection is a must, Data downloaded is over 100 MB.
Or there is another way.

Can download the required files on your PC.
Then on your "N900" open the terminal. Goto /home/user/MyDocs
Make folder named .nitdroid
paste all the files downloaded on the pc to this folder.

Then start the nitdroid installer, it will just pick up the files from the newly created folder.
Neat isn't it :)

Having a phone which dual boots is a dream come true, one of my ultimate tech fantasies.
Currently i have both Maemo 5 and NITDroid on my phone, and am waiting for meego community build for N900 to comes out sometime in october, so that i can triple boot and attain Moksha :)

NOTE: If anybody is facing problem post install in getting the NITDroid to work, try using some other SD Card, it might just work for you.