Consider following example code:
#include <iostream>#include <inttypes.h>using namespace std;int f(uint32_t i){ return 1;}int f(uint64_t i){ return 2;}int main (){ cout << sizeof(long unsigned) << '\n'; cout << sizeof(size_t) << '\n'; cout << sizeof(uint32_t) << '\n'; cout << sizeof(uint64_t) << '\n'; //long unsigned x = 3; size_t x = 3; cout << f(x) << '\n'; return 0;}
This fails on Mac OSX with:
$ g++ --versioni686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)$ make testg++ test.cc -o testtest.cc: In function 'int main()':test.cc:23: error: call of overloaded 'f(size_t&)' is ambiguoustest.cc:6: note: candidates are: int f(uint32_t)test.cc:10: note: int f(uint64_t)make: *** [test] Error 1
Why? Because 'size_t' should be unsigned and either 32 bit or 64 bit wide. Where is the ambiguity then?
Trying the same with 'unsigned long x' instead of 'size_t x' results in ananalogous ambiguity error message.
On Linux/Solaris systems, testing with different GCC versions, different architectures etc. there is no ambiguity reported (and the right overload is used on each architecture).
Is this a Mac OS X bug or a feature?