Warnings suggest compiler confusion between 32 and 64 bit code.
Warnings suggest compiler confusion between 32 and 64 bit code.
- Subject: Warnings suggest compiler confusion between 32 and 64 bit code.
- From: Brian Bruinewoud <email@hidden>
- Date: Mon, 22 Jun 2009 22:09:33 +1000
Hi all,
In a custom view I have the following code (simplified for the purpose
of this post):
- (void)drawRect:(NSRect)rect
{
// Drawing code here.
NSRect bounds = [ self bounds ];
NSLog( @"size of CGFloat %d, float %d, double %d, literal float
%d, literal %d, long literal %d",
sizeof( CGFloat ), sizeof( float ), sizeof( double ), sizeof( 0.0f ),
sizeof( 0.0 ), sizeof( 0.0L ));
CGFloat x = bounds.origin.x;
CGFloat y = bounds.origin.y;
CGFloat c = 0.0L; /
************************************************************ BATCH 3 **/
[[ NSColor colorWithDeviceRed: c green: c blue: c alpha: 0.33L ]
setFill ]; /** BATCH 1 **/
NSRect area = NSMakeRect( x, y, x, y ); /
************************************** BATCH 2 **/
}
The code works as expected but I get the following warnings:
The line at BATCH 1:
warning: passing argument 1 of 'colorWithDeviceRed:green:blue:alpha:'
as 'float' rather than 'double' due to prototype
warning: passing argument 2 of 'colorWithDeviceRed:green:blue:alpha:'
as 'float' rather than 'double' due to prototype
warning: passing argument 3 of 'colorWithDeviceRed:green:blue:alpha:'
as 'float' rather than 'double' due to prototype
warning: passing argument 4 of 'colorWithDeviceRed:green:blue:alpha:'
as 'float' rather than 'double' due to prototype
The line at BATCH 2:
warning: passing argument 1 of 'NSMakeRect' as 'float' rather than
'double' due to prototype
warning: passing argument 2 of 'NSMakeRect' as 'float' rather than
'double' due to prototype
warning: passing argument 3 of 'NSMakeRect' as 'float' rather than
'double' due to prototype
warning: passing argument 4 of 'NSMakeRect' as 'float' rather than
'double' due to prototype
The line at BATCH 3:
(no warnings)
Note that if I change the assign of c to just plain 0.0 (ie, no L) I
get the following warnings:
The line at BATCH 1:
(as above)
The line at BATCH 2:
(as above)
The line at BATCH 3:
warning: implicit conversion shortens 64-bit value into a 32-bit value
Note that the NSLog line logs this:
size of CGFloat 4, float 4, double 8, literal float 4, literal 8, long
literal 16
What's going on?
NSLog shows that CGFloat is a float.
GCC complains about storing an 8 byte floating point literal into a 4
byte floating point literal but is silent when storing a 16 byte
floating point literal... weird.
The prototypes of expect floats and I'm giving floats. So why the
warnings?
I vaguely recall that there's some old C rule that says all floats are
passed as doubles (and all ints shorter than int are passed as int or
something) but
a) I'm not sure that applies in C99
b) GCC should be clever enough to not provide a warning in this instance
c) It didn't in the past and I don't recall changing the GCC settings
in my project - it's not something I've bothered with yet.
Any ideas or suggestions?
thanks,
Brian
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden