I want to be able to do this in my preprocessor macros
#define dble double
/* Just something that converts x to a double precision float.
static_cast used as an illustration: */
#define dble(x) static_cast<double>(x)
I know that overloading is not allowed by the C standard preprocessor. I also know that variadic arguments like
#define dble(...)
requires at least one argument, and omitting the parenthesis is not allowed. Even by the insight of that I cannot let go of the feeling that it must be a way to solve this problem. Do anyone have any smart ideas how it can be done?
Example of use:
dble x;
x = dble(3);
Background: I am actually interested in using the C preprocessor for my Fortran code. I want to develop a simplified notation for variable declarations. DBLE would expand to DOUBLE PRECISION for standalone applications, or REAL(C_DOUBLE) if I am compiling for C-interoperability for a library with C interface. However, DBLE is a so called INTRINSIC in Fortran. DBLE(3) casts 3 to a double precision float. In standalone mode it would be 3.0d0. In C-interoperability mode it would be converted to 3.0_C_DOUBLE.