Hi everyone!
All my programming time i have spent programming on windows and using
microsoft visual c++ 2010
Since i felt that i need linux i started coding and convering my code for linux.
code for:microsoft visual c++ 2010 compiler (32 bit)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
void testing( void *in )
{
int *a = (int *)in;
cout << "a:" << *a << endl;
}
void testing2( void *in )
{
char *c = (char *)in;
cout << "c:" << c << endl;
}
void testing3( void *in )
{
int a = (int)in;
cout << "a:" << a << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
int a = 20;
testing( &a );
a = 24;
testing3( (void *)a );
char c[64] = "Hello world";
testing2(c);
testing2("why g++?");
system("pause")
}
|
code for:linux g++ (64 bit)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
void syspause()
{
do
{
cout << "Press a key to continue..." << endl;
}
while (cin.get() != '\n');
}
void testing( void *in )
{
int *a = (int *)in;
cout << "a:" << *a << endl;
}
void testing2( void *in )
{
char *c = in;
cout << "c:" << c << endl;
}
void testing3( void *in )
{
int a = (int)in;
cout << "a:" << a << endl;
}
int main()
{
int a = 20;
testing( &a );
a = 24;
testing3( (void *)a ); // error
// makes sense since void * in 64bit system is 64bit and int is still
// 32bit. In 32 bit system, both are 32bit so why they work are clear
// for me for now, however if g++ compiler see that
// it should automatically treat that conversion
// as done with testing() function
char c[64] = "Hello world";
testing2(c);
testing2("why g++?"); // this here is why i created thread
syspause();
return 1;
}
|
Why does my win32 compiler let me pass const char * into char * and
g++64 compiler not?
I know i can do:
1 2
|
char s[9] = "why g++?";
testing2(s);
|
but why should i add one extra line?
Why can't compiler do that for me?
Is there any way i can compile my microsoft visual c++ 2010 compiler's
code in linux without editing my code?
I'm not sure what other surprises g++64 compiler holds since i've been working
with it very little.
edit:
i think i found a solution what is actually not bad:
1 2 3 4 5 6 7 8 9 10 11
|
void testing( const void *in ){
char *p = in;
cout << "p:" << p << endl;
}
int Main() {
testing("Hi!");
char p[32] = "hello world!";
testing(p);
return 0
}
|