unnecessary (?) Xcode warning
I'm running Xcode in OS X 10.6 on a Core 2 Duo. Here's a short program:
#include <stdio.h>
int main () {
long a = 8589934592L;
printf("a = %li\n", a);
return 0;
}
When I compile this from the command line (gcc -pedantic) I get no errors or warning. When I compile this in Xcode in debug configuration, I get no errors or warnings. When I开发者_StackOverflow社区 compile this in Xcode in release configuration, I get a warning: "Overflow in implicit constant conversion".
Longs should be 64-bit. And the program runs fine. So what's going on, and how do I get rid of this warning?
Check sizeof(long)
and sizeof(long long)
to see if your assumption about long
being a 64-bit type is correct.
I just tried your program out with Xcode 3.2.1 on Mac OS X 10.6.1 and didn't get that warning. I did manage to get the warning by setting the target configuration to "32-bit universal" instead of "Standard 32/64-bit universal". Make sure you're building for the right machine type!
In the build settings, check "Architectures". If this is "Standard (32/64-bit universal)", then universal binaries with 32 bit and 64 bit versions will be built. The warning is for the 32 bit build.
The difference you're seeing is from "Build Active Architecture Only" being checked in Debug configuration, but not in Release configuration. So the 32 bit version is not built when you compile for Debug on 64 bit, and thus there's no warning.
The problem here is that longs are 32-bit, not 64. long long is 64 bit.
On a Mac Pro running 10.6
#include <stdio.h>
int main() {
printf("%d.\n", sizeof(long));
printf("%d.\n", sizeof(long long));
}
outputs
4.
8.
精彩评论