Thursday, March 29, 2007

What kind of Superhero or SuperVillian are you

These are results for me... check it out..

What Kind of SuperHero are you ?

Your results:
You are Spider-Man

You are intelligent, witty, a bit geeky and have great power and responsibility.




Spider-Man
75%
Superman
70%
Green Lantern
70%
Robin
55%
The Flash
45%
Supergirl
35%
Wonder Woman
35%
Iron Man
30%
Batman
20%
Hulk
10%
Catwoman
5%


What Kind of SuperVillian are you ?
Your results:
You are Mr. Freeze

You are cold and you think everyone else should be also, literally.



Mr. Freeze
58%
Dr. Doom
51%
Mystique
40%
The Joker
39%
Lex Luthor
38%
Venom
36%
Riddler
36%
Apocalypse
33%
Dark Phoenix
33%
Catwoman
31%
Poison Ivy
30%
Juggernaut
28%
Two-Face
24%
Magneto
23%
Kingpin
21%
Green Goblin
20%


Click here to take the Superhero Personality Test

Click here to take the Supervillain Personality Quiz


General Post Ring - New Post
General Post Ring - Old Post

Friday, March 09, 2007

C++ Questionaire

Some interesting questions asked in C++ tests
Enjoy !!!

1) Will the following program execute?

void main()
{
void *vptr = (void *) malloc(sizeof(void));
vptr++;
}

It will throw an error, as arithmetic operations cannot be performed
on void pointers. It will not build as sizeof cannot be applied to void* ( error “Unknown size” )

However, According to gcc compiler it won’t show any error, simply it executes. but in general we can’t do arthematic operation on void, and gives size of void as 1.
The program compiles in GNU C while giving a warning for “void main”. The program runs without a crash. sizeof(void) is “1″ hence when vptr++, the address is incremented by 1.

However gcc is a C compiler. When compiled in g++, g++ complains that the return type cannot be void and the argument of sizeof() cannot be void. It also reports that ISO C++ forbids incrementing a pointer of type ‘void*’.



2) Will it execute or not?

void main()
{
char *cptr = 0?2000;
long *lptr = 0?2000;
cptr++;
lptr++;
printf(” %x %x”, cptr, lptr);
}

0?2000 cannot be implicitly converted to a pointer.

Compiling with VC7 results following errors:
error C2440: ‘initializing’ : cannot convert from ‘int’ to ‘char *’
error C2440: ‘initializing’ : cannot convert from ‘int’ to ‘long *

Program does executes in C

The printout:
2001 2004

compiled with some warnings:
warning C4047: ‘initializing’ : ‘char *’ differs in levels of indirection from ‘int’
warning C4047: ‘initializing’ : ‘long *’ differs in levels of indirection from ‘int’

Solution is casting needs to be done. The format has to be:
int *a = (int *)2000;



3) Whats the solution ?

#include "iostream.h"

class example
{
private :
int i;
float j;

public :

example (int ii=0, float jj=0.0)
{
i = ii; j = jj;
}

void showdata()
{
cout << i << j;
}

friend example operator *(example k, example l);
};

example operator *(example k, example l)
{
example temp;
temp.i = k.i*l.i;
temp.j = k.j*l.j;
return (&temp);
}

void main ()
{
example e1(10,3.14);
example e2(1,1.5);
example e3,e4,e5;

e3 = e1 * 2;
e4 = 2 * e2;
e5 = e1 * e2 * 2;

e3.showdata();
e4.showdata();
e5.showdata();
}


a) Error "Cannot access private data of class example"
b) Error "No legal conversion of return value to return type class example *"
c) Either a or b
d) Neither a or b


Answer:- (B) :- error C2664: 'example::example(int,float)' : cannot convert parameter 1 from 'example *__w64 ' to 'int'

4) Whats the solution ?

#include "iostream.h"

class Base
{
public:
virtual void fun1()
{
cout << "fun1 of base";
}
};

class der1: public Base
{
public:
void fun1()
{
cout << "fun1 of der1";
}

virtual void fun2()
{
cout << "fun2 of der1";
}
};

class der2 : public der1 {};

void main()
{
Base *b;
der2 d;
b = &d;
b->fun1();
b->fun2();
};


a) Code runs successfully
b) Error: fun2 is not a member of Base
c) Error: cannot convert from class der2 to class Base
d) Error: cannot convert from class Base to class der2

Answer:- (B):- error C2039: 'fun2' : is not a member of 'Base'

5)Whats the solution ?

#include "iostream.h"

class Sample
{
int i;

public:
Sample(Sample S)
{
i=S.i;
}
};

void main()
{
Sample S1;
Sample S2 = S1;
}


a) Error: Class must contain a zero argument constructor;
b) Error: Illegal copy constructor
c) Error: Illegal initialisation
d) None above


Answer:- (A) :- error C2512: 'Sample' : no appropriate default constructor available

6)Whats the output ?

#include "iostream.h"

void main()
{
class xx
{
public:
int x=0;
char name [] = "hello";
};

class xx *s;
cout << s->x;
cout << s->name;
}

Output ?

Answer:-
error C2864: 'main::xx::x' : only static const integral data members can be initialized within a class
error C2864: 'main::xx::name' : only static const integral data members can be initialized within a class

7)Whats the output ?

#include "iostream.h"

class counter
{
unsigned int count;

public:
counter()
{
count = 0;
}

int getcount()
{
return count;
}

void operator ++ (int x)
{
count ++;
}
}

void main()
{
counter c1, c2;
cout<< c1.getcount();
cout<< c2.getcount();
c1 ++;
c2 ++;
cout<< c1.getcount();
cout<< c2.getcount();
}

Output ?

Answer:- 0011

8)Whats the output ?

#include

union base
{
private:
int i;
float j;
};

union derieve:public base
{
private:
int i;
};

void main()
{
cout<< sizeof(union derieve);
}

Output ?

Answer:- error C2570: 'derieve' : union cannot have base classes

9)Whats the solution ?

#include "iostream.h"
#include "malloc.h"

void * operator new (size_t s)
{
void *q = malloc(s);
return q;
}

void main()
{
int *p = new int;
*p = 25;
cout << *p;
}

a) We cannot overload new
b) We cannot overload new globally
c) No problem
d) None above


Answer:- (C) :- On execution, "25" is displated

10)Whats the solution ?

#include "iostream.h"
float divide (float a, int b)
{
return (a/b);
}

float divide(float a, float b)
{
return (a/b);
}

void main()
{
int x=5, y=2;
float n=5.0, m= 2.0;
cout << divide(x,y);
cout << divide (n,m);
}

a) Program will not compile
b) 2, 2.5
c) Compile but display garbage value
d) 2.5, 2.5

Answer:- (D)


Programming Ring - New Post
Programming Ring - Old Post

Thursday, March 08, 2007

C++ Linkages...


Well there are many things in development that one has to learn the hard way. By hard way, I mean one gets stuck in some problem and then fight over it or days. Then when you come to understand the problem, you realize why your peers had implemented a certain thing in a certain way. And when you realize this, you feel through respect for them and never forget the problem ever again.

I went through a same problem. This time I was migrating certain applications from one product which used VC 6.0 to another product which used VC.Net. The newer product was based on the older product, meaning the older product acted as a platform and newer stuff was developed on it. So plugins developed on older product used to work on newer product. The problem used to arise at the time of migration. Since the build system was different (newer product used scons) many modifications where made to #define.

I will briefly talk about problems I faced and reason for them. For most experienced developers, this will be child’s play.



1) LINK 2001:- unresolved external symbol error

a) The .h or .cpp file containing the symbol is not getting included. Meaning the lib which contains the symbol is not getting loaded. Check the Makefile or the Build script files to see that the lib path is include.

b) The Lib might be getting included. In that case, open the lib in notepad and search of the symbol. Check if the symbol is present in the lib file. If it is not, then one has forgotten to do dllexport. ( This is case of implicit linking )

c) In the case of one file including .h file present in another dll. Meaning building one dll but internally there is linking to another dl. Now the second dll, as per __declspec(dllimport) gets imported but some where down it is again getting exported because of __declspec(dllexport). This error will occur mostly in case for static variables of a class. Refer below of method to avoid this problem.



2) LINK 2005:- already defined in obj ….

a) The called dll is getting imported and exported as in case of issue 1c.

b) If the above is not a problem, check whether the functions for which problems exist are inline functions. If they are inline functions then make them non inline. Functions are made inline by either using keyword Inline or by defining them in the class declaration itself.



How to avoid problem of multiple import and export

1) Setup a common environment variable which one can use and forget about the import and export headache

Example:-
Suppose we want to build a dll called TAR and it internally contains number of .h and .cpp file. In one of .h file, usually where one puts all #define or the one being include by all .h and .cpp files we put the following definition

#if defined (_WIN32)
#ifdef DASH_WINEXPORT
#define DASH _WINEXPORT __declspec(dllexport)
#else
#define DASH _WINEXPORT __declspec(dllimport)
#endif
#else
#define DASH _WINEXPORT
#endif



Now in the build script file or the makefile or pro file for the TAR।dll,
make sure to define the variable TAR_WINEXPORT

So now when the TAR dll is being built, the variable TAR_WINEXPORT will get set via the build script. This results in TAR_WINEXPORT being set the value __declspec(dllexport) and all the symbols will get exported.

Now suppose one is building a dll called DASH and one of the files is including a .h file who’s symbolic reference is present in the TAR library. So now when one builds the DASH library, the TAR library will get only imported as in the DASH library building script, we have not set the TAR_WINEXPORT variable. So the value of TAR_WINEXPORT becomes __declspec(dllimport) and hence during building of DASH library, the TAR library will get only imported and not exported out again.

In the DASH library the exporting variable will be as follows

#if defined (_WIN32)
#ifdef DASH_WINEXPORT
#define DASH _WINEXPORT __declspec(dllexport)
#else
#define DASH _WINEXPORT __declspec(dllimport)
#endif
#else
#define DASH _WINEXPORT
#endif



2) In the above case, we have defined two export variables for two
libraries/dll’s. So if number of dll’s increase, number of variables increases.

To avoid that one can simply set one single variable for the whole. Consider the following case.

We have are going to set only one variable for purpose of exporting individually in each file.

Now consider that we have a tar\t.h file which is used for creating TAR library.
Let’s have a dash\d.h file which is internally doing #include<../tar/t.h>. The d.h file is used for creating DASH library. So the layout of both files will be as follows.

d.h

#ifdef _WIN32
#undef GLOBAL_WINEXPORT
#define GLOBAL_WINEXPORT __declspec(dllimport)
#endif



#define DLLIMP
#include "../tar/t.h”
#define undef DLLIMP



#ifndef DLLIMP
#ifdef _WIN32
#undef GLOBAL_WINEXPORT
#define GLOBAL_WINEXPORT __declspec(dllexport)
#endif
#endif


t.h

#ifdef _WIN32
#undef GLOBAL_WINEXPORT
#define GLOBAL_WINEXPORT __declspec(dllimport)
#endif



#ifndef DLLIMP
#ifdef _WIN32
#undef GLOBAL_WINEXPORT
#define GLOBAL_WINEXPORT __declspec(dllexport)
#endif
#endif


So now while linking, when t.h is called, the variable DLLIMP is set. As per the
definition in t.h file, since DLLIMP is set, the __declspec(dllexport) part won’t be called and the dll will only get imported.

When building of TAR dll, since the variable DLLIMP is not set, the dll will get exported out, which is as required.

Generally use solution one as it is easier to manage but it’s all up to developers choice



Programming Ring - New Post
Programming Ring - Old Post

The Name Goremaniac

Well every wondered where the name Goremaniac came from ....

It all began in April 2004. I was working in ANSYS software. One of the hobbies or rather past time for everyone during lunch break was to finish lunch quickly, and then log on to miniclip.com and start playing those flash games.

One of the games was Runescape. I personally never tried it because from description at least i thought it was really confusing. My best friend Raghav however played it and said

"gore, try it man, it is nice and simple"

Well, I created a account called "akadubakadu". It's still alive. !!

Game’s starting point is Lumbridge town. Had no clue what was happening. Walked to the draynor village which lies to west of lumbridge. I was carrying all my stuff with me. Didn’t know how to use the bank exactly. So full loaded with all novice stuff, I went fishing for shrimps. After catching few and cooking them I was getting hang of it.

But nothing is so straight forward in life and also in virtual world. I was there, peacefully fishing, being called a terrorist by some Australia player when suddenly a fish came out from fishing spot and by net disappeared. I was stumped. Had no idea what had happened. When asked people how to get new net, they directed me to Catherby, a members playing area for buying new net. Disappointed I decided to chop some trees and level up my wood cutting. Guess what, tree spirit appeared and killed me.

I was back in lumbridge with only 3 things. Don't remember what those things where, but one was wooden shield. I again made my way to draynor village. This time made my way straight to the bank. However, in between lays a prison. And those prison guards are pretty aggressive. I think I walked pass their fence and they attacked me. I ran foolishly ran inside the fence, and two more attacked me. I was surrounded, however only one can attack at a time in that area. I again died not knowing what mistake I made or why the guards attacked me and not the other players.

So back in Lumbridge, I made a note of not going to draynor again and instead I went north. After crossing the bridge and not being allowed into Al-Kharid, I went straight north. But as usual, my adventure spirit got better of me and diverted from main road and took path from behind the champion's guild. I arrived at the mining area besides the champion’s guild and started mining. All of sudden I was attacked by some character. I thought, why is a player attacking me !!!

All other players around me started shouting
"run noob run !!!"

Well being a noob, I didn’t understand that they where addressing me :D

Well I died.

And that was too much for me. Died thrice in 1 hour. I was furious and wanted to take revenge on the theif who killed me!!! It was actually a non playable character of the game that attacked me.

I had to think of some new name, something reflecting some part of my name. And I came up with Goremaniac. As u might have guess, Gore is my surname.

That's how the characted Goremaniac came to be. And I took my revenge. When I was strong enough, I killed that NPC thief 25 times. And still when I pass via that area, I make it a point to kill it atleast once. :D

Akadubakdu is still alive. I play using that character sometimes. Almost lvl 12 now. Now I think he will be able to get his revenge.

- Goremaniac



General Post Ring - New Post
General Post Ring - Old Post