"Cannot convert" double (*) () noexcept 'to' double 'on initialization' when defining max double

I read that the standard way to use the C ++ maximum double value is std::numeric_limits<double>::max


Then, in each of my functions where I want to initialize my doubles as max double, I use:

#include <limits>
#define MAX_DOUBLE (std::numeric_limits<double>::max)


Using gcc -pedantic -pedantic-errors -Wall -Wextra -Werror I get the following error:

Cannot convert 'double (*)() noexcept' to 'double' in initialization


Can you explain this error?


source to share

3 answers


is a function in the global namespace, not a constant. If you create a macro you need to specify the definition as a function identifier

#define MAX_DOUBLE std::numeric_limits<double>::max()


So passing MAX_DOUBLE in a double identifier, as the error message indicates, means initializing the double with a function pointer, which in this case is of type double (*)() noexcept

, causing a type mismatch.

Finally, for all the practical purposes DBL_MAX

defined in the climits , it had to serve your purpose, and thus you would not go through this agony,



As stated in the error message, you are directly using the function pointer ( double (*)() noexcept

) as double

. std::numeric_limits<double>::max

is declared as a function, you need to call it to get the value.

You can change

#define MAX_DOUBLE (std::numeric_limits<double>::max)



#define MAX_DOUBLE (std::numeric_limits<double>::max())




You need to define it as:

#define MAX_DOUBLE std::numeric_limits<double>::max()




All Articles