固定宽度浮动类型在哪里?
C标准固定宽度浮点类型是什么?它们在哪里定义?
Misra-C:2004,规则6.3:typedefs
指示大小和签名的应代替基本数值类型。
Misra-C:2004,规则6.3 ISO(POSIX)TYPEDEFS是:
typedef char char_t;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
typedef float float32_t;
typedef double float64_t;
typedef long double float128_t;
在我的公司我们使用C-99。
IAR电子工作台,第8.4版
我们在Misra-C:2004,因为他们投票不升级Misra,这将需要创建验证测试协议并运行协议。
平台是运行Microcos操作系统的ARM Cortex M。
这是详细的问题:
- 固定宽度浮点类型的类型是什么?
- 什么包括文件内部(或由编译器定义为默认值)?
What are the C standard fixed width floating point types and where are they defined?
From MISRA-C:2004, Rule 6.3:typedefs
that indicate size and signedness should be used in place of the basic numerical types.
The MISRA-C:2004, Rule 6.3 quotes that ISO (POSIX) typedefs are:
typedef char char_t;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
typedef float float32_t;
typedef double float64_t;
typedef long double float128_t;
At my company we are using C-99.
IAR Electronic Workbench, version 8.4
We are at MISRA-C:2004 because they voted not to upgrade MISRA, which would require create a validation test protocol and running the protocol.
Platform is ARM Cortex M running MicroCOS operating system.
Here are the detailed questions:
- What are the typedefs for the fixed width floating point types?
- What include file are they inside (or are they defined as default by the compiler)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
c标准固定宽度浮点类型未定义
c浮点(FP)目标旨在包含变化和许多实现。
MISRA FP目标是限制多样性。
固定尺寸的FP类型不会导致均匀的位编码或其他一致的FP属性。它们在C中的实用性有限 - 因此它们不属于C标准或库的一部分。
fall-back
代码可以在下面使用,
_STATIC_ASSERT
(自C11)或C99 替代。进一步的注释
兼容C可能没有所有32、64、128位FP类型,因此无法定义所有
float32_t,float64_t,float128_t
。2种不同的C实现可能具有32位FP类型,但编码不同。比较 float32 。
2不同的C实现可能具有32位FP类型,即使他们的整数Endians同意,但相同的编码也可能具有不同的Endians。
规则6.3(咨询):应用指示尺寸和签名的类型和签名使用基本的数值类型。:该目标“有助于阐明存储的大小”而不是其他。
规则1.5(咨询):浮点数应符合定义的浮点点标准。特别难以实现。即使实现使用相同的fp编码与 ieee 754 ,C允许操作足够定义的操作定义了与IEE 754不同的行为。
理想情况下,在C中,符合IEEE 754的实现定义了
__ stdc_iec_559 __ __
。然而,证明和维持的合格足够挑战,以至于实现可以放弃定义__ stdc_iec_559 __
,因为它可能仅为99.999%。C standard fixed width floating point types are not defined
C floating point (FP) goals are designed to embrace variations and many implementations.
MISRA FP goals are to restrict variety.
Fixed size FP types do not result in uniform bit encoding nor other consistent FP properties. They have limited usefulness in C - hence they are not part of the C standard or library.
Fall-back
Code could use below and a
_Static_assert
(since C11) or a C99 substitute.Further notes
Compliant C may not have all 32, 64, 128 bit FP types, thus unable to define all
float32_t, float64_t, float128_t
.2 different Compliant C implementations may have a 32-bit FP types, but different encoding. Compare float32 vs. CCSI resulting in different range, precision and sub-normal support.
2 different Compliant C implementations may have a 32-bit FP types with the same encoding, but different endians, even if their integer endians agree.
Rule 6.3 (advisory): typedefs that indicate size and signedness should be used in place of the basic numerical types.: that goal "helps to clarify the size of the storage" and not much else.
Rule 1.5 (advisory): Floating-point implementations should comply with a defined floating-point standard. is particularly difficult to achieve. Even if an implementation uses the same FP encoding as IEEE 754, C allows the operations enough implementation defined behavior to differ from IEE 754.
Ideally, in C, an implementation that conforms to IEEE 754 defines
__STDC_IEC_559__
. Yet proving and maintaining conformity is challenging enough that an implementation may forego defining__STDC_IEC_559__
as it may only be 99.999% conforming.没有。
固定宽度FP类型可能不足以实现OP的更高级别(未说)目标。
如果存在固定宽度的浮点,则可能只能构成固定宽度。如果不是肯定会导致固定范围,精度,编码等
。如果要与之相处,请考虑使用一系列
#if
测试常见的FP编码特征,然后简单地使用float,double double,long double
。There are none.
A fixed width FP type is likely insufficient for OP's higher level (unstated) goal.
If a fixed width floating point existed, it may only make for a fixed width. If would not certainly make for a fixed range, precision, encoding, etc.
If a fixed width floating point also defined encoding, portability is reduced. If will to live with that, consider instead a series of
#if
tests for common FP encoding characteristics and simply usefloat, double, long double
.显然(非官方来源),Misra-C:2004年第6.3条说:
这是不好的措辞。这并不意味着POSIX或任何ISO标准提供这些
typedef
声明。这意味着与Misra符合的软件, IE ,您正在编写的软件本身定义这些typedef
名称并使用它们。如果这不是规则的预期含义,则该规则是错误的,暗示这些类型是由POSIX指定的,因为
float64_t
未出现在Posix 2008规范中。 (我没有检查较早的版本;我假设它是否出现在早期版本中,至少会在Posix 2008版本中提及它。)Apparently (unofficial source), MISRA-C:2004 rule 6.3 says:
This is bad phrasing. It does not mean that POSIX or any ISO standard provides these
typedef
declarations. It means the software conforming to MISRA, i.e., the software you are writing, should itself define thesetypedef
names and use them.If that is not the intended meaning of the rule, then the rule is wrong to imply these types are specified by POSIX, because
float64_t
does not appear in the POSIX 2008 specification. (I did not check earlier versions; I am assuming if it appeared in earlier versions, there would at least be mention of it in the POSIX 2008 version.)