Robby
2010-01-12 17:35:01 UTC
Hello,
Quick question!
Since I have a quite a few variables which must stay as 8 bits, I find
myself having to pass many of these to functions as parameters.
So if I had:
int x;
I am now calling it:
unsigned char x;
To me, "x" is still an 8 bit value which actually simulates my old int's.
However, many of my functions from the 8 bit processor are like this:
void f1(int x);
Which means that "x" in the new 32 bit processor is considered as 32 bits !!!!
I don't want to change any of my function prototypes to:
void f1(unsigned char x);
which means that I would leave them as they are with int's.
So, my question is, in general, do C/C++ compilers do automatic casting when
a parameter in the calling function is one type, but the function definition
is another.
For example, if I do this:
======================
void f1(int x)
{x++;}
int main(void)
{unsigned char x=10;
f1(x);
return 0;}
======================
should I trust the compiler to do the necssary cast from char to int?
*OR*
should I always do it myself, like this:
======================
void f1(int x)
{x++;}
int main(void)
{unsigned char x=10;
f1((int) x);
return 0;}
======================
Thnakyou all for your help!
Quick question!
Since I have a quite a few variables which must stay as 8 bits, I find
myself having to pass many of these to functions as parameters.
So if I had:
int x;
I am now calling it:
unsigned char x;
To me, "x" is still an 8 bit value which actually simulates my old int's.
However, many of my functions from the 8 bit processor are like this:
void f1(int x);
Which means that "x" in the new 32 bit processor is considered as 32 bits !!!!
I don't want to change any of my function prototypes to:
void f1(unsigned char x);
which means that I would leave them as they are with int's.
So, my question is, in general, do C/C++ compilers do automatic casting when
a parameter in the calling function is one type, but the function definition
is another.
For example, if I do this:
======================
void f1(int x)
{x++;}
int main(void)
{unsigned char x=10;
f1(x);
return 0;}
======================
should I trust the compiler to do the necssary cast from char to int?
*OR*
should I always do it myself, like this:
======================
void f1(int x)
{x++;}
int main(void)
{unsigned char x=10;
f1((int) x);
return 0;}
======================
Thnakyou all for your help!
--
Best regards
Roberto
Best regards
Roberto