Ubuntu: Where is `__FLT_MAX__` constant defined on Ubuntu?



Question:

I am learning C programming using gcc compiler under Ubuntu 14.04 (64bits). As a practice, I am trying to locate the definitions of size limits of multiple C data types.

I have easily located limits.h in /usr/include, and found the explicit definitions of constants such as

#  define INT_MAX   2147483647  

in it.

I Also found out that float.h is located in /usr/lib/gcc/x86_64-linux-gnu/4.8/include. However, I didn't find the explicit defintion of, say, FLT_MAX. What I got is

#define FLT_MAX     __FLT_MAX__  

But where is the definition of __FLT_MAX__? Or where does the C preprocessor get the value of it?

Reference: Here is a thread on Ubuntu Forums which also asked the same question (but didn't get solved).


Solution:1

__FLT_MAX__ is a pre-defined macro. You'll probably have to look inside the GCC source to see where it is defined, but it's easy to what it is defined to:

The C preprocessor normally predefines several macros that indicate what type of system and machine is in use. They are obviously different on each target supported by GCC. This manual, being for all systems and machines, cannot tell you what their names are, but you can use cpp -dM to see them all.

So:

$ cpp -dM <<<'' | grep 'FLT_MAX'  #define __FLT_MAX_10_EXP__ 38  #define __FLT_MAX_EXP__ 128  #define __FLT_MAX__ 3.40282346638528859812e+38F  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »