Hi, all. My question is about the convention of the standard namespace in C++. firstly, let's read the following classic example in C/C++:
,----------------------------- | #include <cstdio> | #include <cmath> | | double fabs(double a) | { | return -1.0*a; | } | | int main() | { | double b=fabs(3.0); | double c=std::fabs(3.0); | printf("%f, %f\n",b,c); | } `----------------------------- The Xcode (or Apple Clang) gives the results with both 3.000000. I have tried to compile the same code by GCC on Fedora 22 and obtain the opposite results with both -3.000000. It's ridiculous since fabs and std::fabs are lying in different namespaces. I also compile the following C/C++ codes: ,----------------------- | #include <cstdio> | #include <cmath> | | int abs(int a) | { | return -1*a; | } | | int main() | { | int b=abs(3); | int c=std::abs(3); | printf("%b, %c\n", b, c); | } `----------------------- in Xcode. Now, it gives me the error about ambiguous calling to std::abs function while GCC gives me the right answer. After browsing the hierarchy of C/C++ headers ,------------------------------------------------------------------------------------------------------------------ | $ cd /Applications/Xcode.app/Contents | $ find . -iname 'cmath' | ./Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/c++/4.2.1/cmath | ./Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/c++/4.2.1/tr1/cmath | ./Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/c++/4.2.1/cmath | ./Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/c++/4.2.1/tr1/cmath | ./Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1/cmath | ./Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1/tr1/cmath | ./Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath `------------------------------------------------------------------------------------------------------------------ I found out that Apple Clang doesn't offer the newest math library. Anyone knows what happened between math library and standard namespace? Best wishes, Jun-Qi Hu
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com