c++ - Is isnan in the std:: namespace? More in general, when is std:: necessary, optional or to be avoided? -
with mingw 4.7.2, have library doesn't compile because of call isnan. compiler says "everything fine" if use std::isnan, , indeed manage compile file.
but if check here (edit: maybe should have checked here :-) ), std:: doesn't seem necessary. if add it, file portable?
more in general, each case there general way understand when putting std:: necessary (for portability), optional or avoided?
edit
indeed among origins of problem there multiple header inclusions, , of included headers include <cmath>, while cpp file tries include <math.h> (when <cmath> has been included).
it depends on header include. if include c header <math.h> (which part of c++, albeit marked deprecated), can use unqualified c functions, isnan. if on other hand include c++ header <cmath>, guaranteed brings functions <math.h> std namespace , have qualify them, std::isnan (or use kind of using directive). unfortunately implementation allowed not required bring functions global namespace, too, when including <cmath> (and 1 of many "works on machine"-incidences of c++ , reason why many people write code tried compile unsuccessfully).
so sum up: either include <math.h> , use isnan or include <cmath> , use std::isnan, else non-portable. of course applies other c header , respective c++ version, too.
edit: should noted though, particular function isnan supported since c++11 , wasn't available in c++98 @ (which may part of confusion). doesn't change in situation because in c++98 neither <cmath> nor <math.h> (which actual c89/c90 header , not c99 header c++11 includes) had function, since they're in-sync. library question maybe tried use c++98 while taking isnan function different c99 implementation (which isn't particularly idea, might conflict c89/c90 parts of c++ implementation, never tried though).
Comments
Post a Comment