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: "Clark Cox" <email@hidden>
- Date: Tue, 27 Nov 2007 09:54:07 -0800
On Nov 27, 2007 9:47 AM, Jens Miltner <email@hidden> wrote:
>
> 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...
[snip]
> 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.
You're missing the point of the warning. Under K&R C (i.e. pre 1989),
there was no such thing as a function prototype. One could not pass
unpromoted values (i.e. all integer values were promoted to at least
an int, and all floating point values were promoted to at least a
double). This warning was to catch places where this change in
behavior could bite people. Nothing more, nothing less.
> Looks like the
> float is implicitely propagated to double just to be propagated to
> float again, which to me doesn't make sense ;-)
That is the way C is defined. All arithmetic expressions involving
float or double are promoted to double, just as expressions involving
int, char or short are promoted to int. (the actual rules are a bit
more involved than that, but you get the gist).
--
Clark S. Cox III
email@hidden
_______________________________________________
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