Re: Warnings About Signedness
Re: Warnings About Signedness
- Subject: Re: Warnings About Signedness
- From: Heath Raftery <email@hidden>
- Date: Sun, 10 Jul 2005 12:15:38 +1000
On 09/07/2005, at 3:39 AM, Lance Drake wrote:
Hi XCode Folks,
The new, ever-pickier (read: more correct and complete)
compilers in XCode 2.1 are spewing zillions of warnings about
'signedness'.
To me, warnings are a big deal as I want every possible warning
the compiler will allow. They don't call them 'warnings' for
nothing. However, it would be nice if I could take on the
responsibility for appropriately dealing with any fallout from the
improper observation of signedness.
Rather than playing with build settings, which effectively hides a
set of warnings that may in the future pick up soemthing you didn't
intend, you could just be a little more deliberate in your code,
couldn't you? So when you're happy to suffer the fallout from a sign
conversion, specify it in the code:
<BAD CODE>
int main(int argc, char *argv[])
{
signed int myInt = -15;
int result = myFunc(&myInt);
printf("myInt = %d, result = %d", myInt, result);
return 0;
}
int myFunc(unsigned int *int1)
{
*int1 = 5;
return 5**int1;
}
</BAD CODE>
Just cast the value that will be implicity converted, so that it is
explicit.
<BETTER CODE>
int main(int argc, char *argv[])
{
signed int myInt = -15;
int result = myFunc((unsigned int *)&myInt);
printf("myInt = %d, result = %d", myInt, result);
return 0;
}
int myFunc(unsigned int *int1)
{
*int1 = 5;
return 5**int1;
}
</BETTER CODE>
Does that help?
Heath
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden