更新时间:2023-02-05 16:21:38
2005年5月31日星期二19:25:27 +0200,jlara< jl * **@wowway.com>写道:
On Tue, 31 May 2005 19:25:27 +0200, jlara <jl***@wowway.com> wrote:
typedef union
uint8 byte;
struct
{
uint8:4;
uint8 bla:4;
uint8 tffca:1;
uint8 tsfrz:1;
uint8 tswai:1;
} bit;
} tSCR1;
#define scr1(*(tSCR1 *)(0x4c))
scr1.bit.ten = 1; / *编译器抱怨这个* /
typedef union
{
uint8 byte;
struct
{
uint8 : 4;
uint8 bla : 4;
uint8 tffca : 1;
uint8 tsfrz : 1;
uint8 tswai : 1;
uint8 ten : 1; /* timer enable */
}bit;
}tSCR1;
#define scr1 (*(tSCR1 *)(0x4c)) scr1.bit.ten = 1; /* the compiler complains about this */
不,它抱怨丢失的字段名称。
Jirka
No, it complains about a missing field name in bit.
Jirka
Jirka Klaue< jk **** @ tkn.tu-berlin.de>写道:
Jirka Klaue <jk****@tkn.tu-berlin.de> wrote:
2005年5月31日星期二19:25:27 +0200,jlara< jl *** @ wowway.com>写道:
On Tue, 31 May 2005 19:25:27 +0200, jlara <jl***@wowway.com> wrote:
typedef union
{u>8 byte;
struct
{
uint8:4;
uint8 bla:4;
uint8 tffca:1;
uint8 tsfrz:1;
uint8 tswai:1;
uint8 ten:1; / * timer enable * /
} bit;
} tSCR1;
#define scr1(*(tSCR1 *)(0x4c))
scr1.bit.ten = 1; / *编译器抱怨这个* /
typedef union
{
uint8 byte;
struct
{
uint8 : 4; uint8 bla : 4; uint8 tffca : 1;
uint8 tsfrz : 1;
uint8 tswai : 1;
uint8 ten : 1; /* timer enable */
}bit;
}tSCR1;
#define scr1 (*(tSCR1 *)(0x4c)) scr1.bit.ten = 1; /* the compiler complains about this */
不,它抱怨丢失字段名称。
No, it complains about a missing field name in bit.
这不是我的编译器(gcc)抱怨的缺少字段名称
关于(标准允许使用未命名的位字段)但是
类型用于比特字段的变量 - unit8不是一个标准类型,它必须是uint8_t。 (假设一个C99 compli-
蚂蚁编译器)然后只为有符号字段签名和无符号
整数可以按照
标准。有了它,它可以毫无问题地编译,
OP指示的行被接受而没有投诉。
如果OPs编译器存在实际问题只有那一行(
我想不应该是这种情况)另一种选择是尝试
使用指向联盟的指针
#defined scr1((tSCR1 *)0x4c)
然后再做
scr1-> bit .ten = 1;
或用于设置重置位的已定义宏,即
#define TIMER_ENABLE()do {(( tSCR1 *)0x4c) - > bit.ten = 1; } while(0)
#define TIMER_DISABLE()do {((tSCR1 *)0x4c) - > bit.ten = 0; } while(0)
,因为这似乎主要是关于代码的可读性,
可能导致最容易阅读的代码。 />
问候,Jens
-
\ Jens Thoms Toerring ___ Je *********** @ physik.fu-berlin.de
\ __________________________ http://www.toerring.de
jlara写道:
代码无法编译:
typedef union
{u>8 byte;
结构
{/ uint8:4;
uint8 tffca:1;
uint8 tsfrz:1;
uint8 tswai:1;
uint8 ten:1; / *定时器启用* /
}位;
} tSCR1;
#define scr1(*(tSCR1 *)(0x4c))
scr1.bit.ten = 1; / *编译器抱怨这个* /
the code does not compile:
typedef union
{
uint8 byte;
struct
{
uint8 : 4;
uint8 tffca : 1;
uint8 tsfrz : 1;
uint8 tswai : 1;
uint8 ten : 1; /* timer enable */
}bit;
}tSCR1;
#define scr1 (*(tSCR1 *)(0x4c))
scr1.bit.ten = 1; /* the compiler complains about this */
代码对我来说是正确的(假设uint8是
unsigned char,而你的编译器支持uint8作为
位域类型)。
确切的编译错误是什么?
另一件事尝试使用除''bit''
和''ten'之外的其他名称,以防这些符号是#defined宏。我使用的一个
编译器有#define bit< something>在其标准
标题中。
The code looks correct to me (assuming that uint8 is
unsigned char, and that your compiler supports uint8 as a
bitfield type).
What is the exact compiler error?
Another thing to try would be to use other names than ''bit''
and ''ten'', in case those symbols are #defined macros. One
compiler I use has #define bit <something> in its standard
headers.