使用联盟时会发出警告 [英] Warning comes when using Unions
问题描述
大家好,
我已宣布联盟如下
typedef union
{
struct interrupt_bits
{
unsigned char c_int_hs_fs_status:1,
c_setup_intflag:1,
c_hs_fs_state:1,
c_int_suspend:1,
c_int_resume:1,
c_bus_reset:1,
c_int_setup :1,
c_int_ep0tx:1,
c_int_ep0rx:1,
c_int_ep2tx:1,
c_int_ep2rx:1 ;
} BITS;
短s_interrupt_flags;
} USB;
USB Usb;
现在当我编译程序时,我收到一条警告信息,说
"警告:位字段的非标准类型。我正在使用Texas
Instruments Cross Compiler(Code Composer Studio)。有人可以建议
如何消除警告信息??
提前谢谢,
Srikanth
Hi all,
I have declared an Union as follows
typedef union
{
struct interrupt_bits
{
unsigned char c_int_hs_fs_status : 1,
c_setup_intflag : 1,
c_hs_fs_state : 1,
c_int_suspend : 1,
c_int_resume : 1,
c_bus_reset : 1,
c_int_setup : 1,
c_int_ep0tx : 1,
c_int_ep0rx : 1,
c_int_ep2tx : 1,
c_int_ep2rx : 1;
} BITS;
short s_interrupt_flags;
}USB;
USB Usb;
Now when I compile the program , I get the a warning message saying
that
" warning: nonstandard type for a bit field". I am using a Texas
Instruments Cross Compiler(Code Composer Studio). Can anybody suggest
how to eliminate the warining message ??
Thanks in advance,
Srikanth
推荐答案
" Kantha" < BJ ********* @ gmail.com>在消息中写道
news:11 ********************* @ i40g2000cwc.googlegro ups.com ...
"Kantha" <bj*********@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
大家好,
我已宣布一个联盟如下
typedef union
struct interrupt_bits
> unsigned char c_int_hs_fs_status:1,
c_setup_intflag:1,
Hi all,
I have declared an Union as follows
typedef union
{
struct interrupt_bits
{
unsigned char c_int_hs_fs_status : 1,
c_setup_intflag : 1,
你还不需要声明每个元素的数据类型吗?
即:
unsigned char c_int_hs_fs_status:1,
unsigned char c_setup_intflag:1,
等等on。
当我按照你的方式尝试时,我得到一个语法错误:标识符在
c_setup_intflag:1行以及余数上的各种其他错误。当我在每个数据类型之前添加
数据类型时,没有错误。
- 比尔
Don''t you still need to declare the data type for each element?
That is:
unsigned char c_int_hs_fs_status : 1,
unsigned char c_setup_intflag : 1,
and so on.
When I try it your way, I get a "syntax error: identifier" on the
c_setup_intflag:1 line and various other errors on the remainder. When I add
data types before each one, no errors.
- Bill
I没有看到它给出错误的原因..,你可以用
方式..,它基本上为
结构中的每个元素分配一个位。
我面临的问题是,虽然程序工作正常:-),我
无法消除警告.. :-(
I dont see a reason why is it giving error..,You can do it in both
ways.., its basically alloting a single bit to each element in a
structure.
The problem i am facing is that although the program works fine :-), I
am not able to eliminate the warning..:-(
Kantha写道:
Kantha wrote:
大家好,
我已宣布联盟如下
typedef union
unsigned char c_int_hs_fs_status:1,
c_setup_intflag:1,
c_hs_fs_state:1,
c_int_suspend:1,
c_int_resume:1,
c_bus_reset:1,
c_int_setup:1,
c_int_ep0tx:1,
c_int_ep0rx :1,
c_int_ep2tx:1,
c_int_ep2rx:1;
} BITS;
短s_interrupt_flags;
} USB;
USB Usb;
现在当我编译程序时,我收到一条警告信息说
警告:位字段的非标准类型。我正在使用Texas
Instruments Cross Compiler(Code Composer Studio)。任何人都可以建议如何消除警告信息??
提前感谢,
Srikanth
Hi all,
I have declared an Union as follows
typedef union
{
struct interrupt_bits
{
unsigned char c_int_hs_fs_status : 1,
c_setup_intflag : 1,
c_hs_fs_state : 1,
c_int_suspend : 1,
c_int_resume : 1,
c_bus_reset : 1,
c_int_setup : 1,
c_int_ep0tx : 1,
c_int_ep0rx : 1,
c_int_ep2tx : 1,
c_int_ep2rx : 1;
} BITS;
short s_interrupt_flags;
}USB;
USB Usb;
Now when I compile the program , I get the a warning message saying
that
" warning: nonstandard type for a bit field". I am using a Texas
Instruments Cross Compiler(Code Composer Studio). Can anybody suggest
how to eliminate the warining message ??
Thanks in advance,
Srikanth
C99第6.7.2.1段说位字段的类型应为_Bool的有限或不合格的版本,带符号的int,unsigned int或
其他一些实现定义的类型。 。我认为早期版本的
语言对此更具限制性。
C99 para 6.7.2.1 says "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". I think earlier versions of
the language were more restrictive on this.
这篇关于使用联盟时会发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!