मैं यहाँ जो isnan
<math.h>
से उपयोग करता है एक छोटे से परीक्षण से ऐप्स है:<cmath> सी ++ 14/सी ++ 11 में <math.h> में इज़न छुपाता है?
#include <iostream>
#include <math.h>
int main()
{
double d = NAN;
std::cout << isnan(d) << '\n';
return 0;
}
बिल्ड और 3 अलग अलग मानकों के अंतर्गत चलाएँ:
$ g++ -std=c++98 main.cpp; ./a.out 1 $ g++ -std=c++11 main.cpp; ./a.out 1 $ g++ -std=c++14 main.cpp; ./a.out 1
अब हम भी <cmath>
शामिल हैं, और isnan
और std::isnan
दोनों के साथ परीक्षण:
#include <iostream>
#include <cmath>
#include <math.h>
int main()
{
double d = NAN;
std::cout << std::isnan(d) << '\n';
std::cout << isnan(d) << '\n';
return 0;
}
बिल्ड और चलाएँ:
सी ++ 98 काम करता है
$ g++ -std=c++98 main.cpp; ./a.out 1 1
सी ++ 11 और सी ++ 14 नहीं है , isnan
नहीं मिला है।
$ g++ -std=c++11 main.cpp main.cpp: In function ‘int main()’: main.cpp:10:25: error: ‘isnan’ was not declared in this scope std::cout << isnan(d) << '\n'; ^ main.cpp:10:25: note: suggested alternative: In file included from main.cpp:3:0: /usr/include/c++/5/cmath:641:5: note: ‘std::isnan’ isnan(_Tp __x) ^ $ g++ -std=c++14 main.cpp main.cpp: In function ‘int main()’: main.cpp:10:25: error: ‘isnan’ was not declared in this scope std::cout << isnan(d) << '\n'; ^ main.cpp:10:25: note: suggested alternative: In file included from main.cpp:3:0: /usr/include/c++/5/cmath:641:5: note: ‘std::isnan’ isnan(_Tp __x) ^
नोट शामिल किए जाने के आदेश महत्वपूर्ण नहीं है। अगर मैं <cmath>
<math.h>
से पहले या उसके बाद, परिणाम समान है।
प्रश्न
- क्यों
isnan
चला गया है? - नए मानक के तहत संकलित करने के लिए वापस जाने और पुराने कोड को बदलने के बिना, क्या इसे ठीक करने का कोई तरीका है?
बजना libC++ का उपयोग कर रहा है, या एक ही libstdC++ कि जीसीसी है? – ildjarn
@ildjarn 'ldd' कहता है कि यह वही है ('/usr/lib/x86_64-linux-gnu/libstdC++। So.6')। मैंने क्लैंग भाग को हटाने के लिए सवाल संपादित कर लिया है। –
अजीब समस्या .. क्या होगा यदि आप cmath और math.h सहित तारों को स्वैप करते हैं? मेरे लिए, मैं सीएम हेडर जैसे सीएमएथ –