简体   繁体   English

严格的ANSI C - 8位结构元素是否违规?

[英]Strict ANSI C - 8 bit struct elements a violation?

I have defined a struct as follows: 我已经定义了一个结构如下:

struct Display7
{
    U8 a : 1;
    U8 b : 1;
    U8 c : 1;
    U8 d : 1;
    U8 e : 1;
    U8 f : 1;
    U8 g : 1;
}Display7;

If I disable Strict ANSI C check in Keil IDE, there is no errors. 如果我在Keil IDE中禁用严格ANSI C检查,则没有错误。 If enable Strict ANSI C, I get the error "non standard type for a bit field". 如果启用严格ANSI C,我会收到错误“位字段的非标准类型”。 What is causing the problem? 是什么导致了这个问题? If I make each struct element as U32,then ANSI C doesn't complain. 如果我将每个struct元素设置为U32,则ANSI C不会抱怨。

Standard is clear about it: 标准很明确:

6.7.2.1 Structure and union specifiers : 5/ A bit-field shall have a type that is a qualified or unqualified version of _Bool , signed int , unsigned int , or some other implementation-defined type. 6.7.2.1结构和联合说明符 :5 /一个位字段的类型应该是_Boolsigned intunsigned int或其他一些实现定义类型的限定或非限定版本。 It is implementation-defined whether atomic types are permitted. 它是实现定义的,是否允许原子类型。

在C99中,具有除signed或unsigned int_Bool之外的类型的位字段是可选的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM