64bit porting

S

shaanxxx

I had programme with 32 arch .

int f(int a)
{

printf("long\n");
return 1;
}
int f(char a)
{

printf("char\n");
return 1;
}
int main()
{

f(1);
return 0;
}


Now I modified it for 64bit arch
int f(long a) // here is problem
{

printf("long\n");
return 1;
}
int f(char a)
{

printf("char\n");
return 1;
}
int main()
{


f(1);
return 0;
}

I have got ambiguity error.

I changed 'int' to 'long', now i am getting error why it is so.

Thanks
Shaan
 
V

Victor Bazarov

shaanxxx said:
I had programme with 32 arch .

int f(int a)
{

printf("long\n");

Printing "long" in a function that takes an 'int'? Talking about
deceiving the user...
return 1;
}
int f(char a)
{

printf("char\n");
return 1;
}
int main()
{

f(1);
return 0;
}


Now I modified it for 64bit arch
int f(long a) // here is problem
{

printf("long\n");
return 1;
}
int f(char a)
{

printf("char\n");
return 1;
}
int main()
{


f(1);
return 0;
}

I have got ambiguity error.

I changed 'int' to 'long', now i am getting error why it is so.

The numeric literal 1 is neither 'long' nor 'char'. It's an 'int'.
To choose between 'f(long)' and 'f(char)' the compiler checks the
rank of the conversion sequences from your type ('int') to each of
the destination types. Both are "integral conversion" and both rank
the same, so the compiler cannot choose.

V
 
P

peter koch

shaanxxx said:
I had programme with 32 arch .

int f(int a)
{

printf("long\n");

Why printf`? If you post to C++, you should know that the idiomatic io
is via streams (here std::cout).
return 1;
}

That print-out is misleading.
int f(char a)
{

printf("char\n");
return 1;
}
int main()
{

f(1);
That "1" in the line above is an int - no matter what platform your
program is on. Obviously it will choose int f(int).
return 0;
}


Now I modified it for 64bit arch
int f(long a) // here is problem
{

printf("long\n");
return 1;
}
int f(char a)
{

printf("char\n");
return 1;
}
int main()
{


f(1);
That "1" above is still an int. The program has to choose between
f(long) (convert from int to long) and f(char) (convert from int to
char). No conversion is better than the other - and thus the compiler
complains: you (the programmer) will have to decide.
return 0;
}

I have got ambiguity error.

I changed 'int' to 'long', now i am getting error why it is so.
/Peter
 
S

shaanxxx

Victor said:
Printing "long" in a function that takes an 'int'? Talking about
deceiving the user...


The numeric literal 1 is neither 'long' nor 'char'. It's an 'int'.
To choose between 'f(long)' and 'f(char)' the compiler checks the
rank of the conversion sequences from your type ('int') to each of
the destination types. Both are "integral conversion" and both rank
the same, so the compiler cannot choose.

V


Thanks all
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top