我想知道 GCC 中 float
的大小,而不必运行编译器。我知道一个选择是编写一个小函数并让编译器打印出一个汇编列表。
有 limits.h
,其中包含最小值和最大值,但是否有类似的东西告诉不同隐式类型的大小?
我在 Windows 7 x64 上使用 GCC;目标平台是 ARM7 32 位模式。语言是 C。
最佳答案
您可以让 GCC 打印出所有默认宏:
gcc -dM -E - </dev/null | grep FLT
然后你会得到这样的行:
#define __FLT_MANT_DIG__ 24
#define __FLT_MAX_EXP__ 128
现在您可以按如下方式解析:
24 + lg(128) + 1 = 32
查找文档:
1) man gcc
:
-E Stop after the preprocessing stage; do not run the compiler proper.
The output is in the form of preprocessed source code, which is
sent to the standard output.
...
-dCHARS
CHARS is a sequence of one or more of the following characters, and
must not be preceded by a space. Other characters are interpreted
by the compiler proper, or reserved for future versions of GCC, and
so are silently ignored. If you specify characters whose behavior
conflicts, the result is undefined.
M Instead of the normal output, generate a list of #define
directives for all the macros defined during the execution of
the preprocessor, including predefined macros. This gives you
a way of finding out what is predefined in your version of the
preprocessor. Assuming you have no file foo.h, the command
touch foo.h; cpp -dM foo.h
will show all the predefined macros.
2) 实际的宏:
http://www.gnu.org/s/hello/manual/libc/Floating-Point-Parameters.html
关于c - 不编译确定 `sizeof float`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7168215/