在不编译的情况下确定`floatof`的大小 [英] Determine `sizeof float` without compilation

查看:134
本文介绍了在不编译的情况下确定`floatof`的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道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 

code>

查找文档:

1) man gcc

  -E在预处理阶段后停止;不要运行编译器。 
输出采用预处理源代码的形式,即
发送到标准输出。

...

-dCHARS
CHARS是一个或多个以下字符的序列,
不能以空格开头。其他字符由编译器解释为
,或者为未来版本的GCC保留,而
则默默忽略。如果您指定行为
冲突的字符,则结果未定义。

M替代正常输出,为预处理器执行
期间定义的所有宏生成#define
伪指令列表,包括预定义的宏。这给你一个
的方法来找出在你的
预处理器版本中预定义的东西。假设你没有文件foo.h,命令

触摸foo.h; cpp -dM foo.h

将显示所有预定义的宏。



<2>实际的宏:

http://www.gnu.org/s/hello /manual/libc/Floating-Point-Parameters.html


I'd like to know the size of a float in GCC, without having to run the compiler. I know one option is to write a small function and have the compiler print out an assembly listing.

There is limits.h, which contains the minimums and maximums, but is there something similar that tells the size of the different implicit types?

I'm using GCC on Windows 7 x64; the target platform is ARM7 32 bit mode. Language is C.

解决方案

You can have GCC print out all of the default macros:

gcc -dM -E - </dev/null | grep FLT

Then you get lines like:

#define __FLT_MANT_DIG__ 24
#define __FLT_MAX_EXP__ 128

Now you can parse this as follows:

24 + lg(128) + 1 = 32

To find documentation:

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) the actual macros:

http://www.gnu.org/s/hello/manual/libc/Floating-Point-Parameters.html

这篇关于在不编译的情况下确定`floatof`的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆