Search code examples
cc-preprocessorlong-double

How can you set data type of #define to long double?


I have a c-code where I define some variables for pre-processing using the #define command.

However, I think that there are ways to toggle between float and double data types by doing for example:

#define 1.0f     // float data type

or

#define 1.0     // double data type

Is there a way I can use it to set a variable of long double data types?


Solution

  • Suffix the float constant with l or L to give it type long double:

    1.0L
    

    Do note that float constants only have meaning to C. As far as the preprocessor is concerned, that's just a string of four characters, no different from any other.