Re: strange compiler warnings - can't get rid of them?
Re: strange compiler warnings - can't get rid of them?
- Subject: Re: strange compiler warnings - can't get rid of them?
- From: Jens Miltner <email@hidden>
- Date: Tue, 27 Nov 2007 18:47:05 +0100
On 27.11.2007, at 18:30, Clark Cox wrote:
On Nov 27, 2007 8:52 AM, Jens Miltner <email@hidden> wrote:
Hi,
I have the following line in my source code:
NSSize warningIconSize = NSMakeSize(iconSize.width * 0.75,
iconSize.height *
0.75);
This line triggers the following errors:
warning: passing argument 1 of 'NSMakeSize' as 'float' rather than
'double'
due to prototype
warning: passing argument 2 of 'NSMakeSize' as 'float' rather than
'double'
due to prototype
The warning is correct (you asked for -Wconversion after all). The
type of the expression (iconSize.width * 0.75) is double, and you are
converting it to a float by passing it to NSMakeSize.
Yes, I know that and I'm fine with this type of warnings in general.
That's why I tried explicitely casting to float or assigning to
temporary variables, both of which didn't get rid of the warning...
-Wconversion largely exists to catch problems when going from K&R C
(where it was quite tricky to pass a 'float' argument) to ANSI/ISO C ,
and as such doesn't have much use in other situations.
Well, it might also warn about floating point numbers being truncated
to integers when passed to functions, correct? In that case, it might
be helpful...
Personally, I'm a believer in cranking up the warnings to the topmost
and adjusting the code to reduce warnings. This should help finding
out about a lot of potential problems at compile time rather than at
runtime...
You can either turn off the warning or use this instead:
NSSize warningIconSize = {iconSize.width * 0.75, iconSize.height *
0.75};
Yes, that will do, but it doesn't solve the general problem of passing
floats to APIs, e.g. any of the following will also report a warning
warning: passing argument 3 of 'compositeToPoint:operation:fraction:'
as 'float' rather than 'double' due to prototype
[warningIcon compositeToPoint:pt operation:NSCompositeSourceOver
fraction:0.9];
[warningIcon compositeToPoint:pt operation:NSCompositeSourceOver
fraction:(float)0.9];
float f = 0.9;
[warningIcon compositeToPoint:pt operation:NSCompositeSourceOver
fraction:f];
Basically the same as when calling NSMakePoint, but in this case, I
don't see an easy way around...
IMHO, this is an incorrect warning, as in two of the above lines, I
explicitely call the API with a float as argument. Looks like the
float is implicitely propagated to double just to be propagated to
float again, which to me doesn't make sense ;-)
</jum>
_______________________________________________
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