GCC按位属性

Nor*_*löw 9 c attributes gcc

GCC __attribute__(bitwise)是什么意思?GCC-4.6的信息页面中未提及该属性.我open-iscsi-2.0.871/include/iscsi_proto.h在源文件中使用了它,它在项目Open-ISCSI中用作它

...
/*
 * If running svn modules we may need to define these.
 * This should not go upstream since this is already properly defined there
 */
#ifdef __CHECKER__
#define __bitwise__ __attribute__((bitwise))
#else
#define __bitwise__
#endif
#ifdef __CHECK_ENDIAN__
#define __bitwise __bitwise__
#else
#define __bitwise
#endif

/*! initiator tags; opaque for target */
typedef uint32_t __bitwise__ itt_t;
/*! below makes sense only for initiator that created this tag */
#define build_itt(itt, age) ((__force itt_t)\
    ((itt) | ((age) << ISCSI_AGE_SHIFT)))
#define get_itt(itt) ((__force uint32_t)(itt_t)(itt) & ISCSI_ITT_MASK)
#define RESERVED_ITT ((__force itt_t)0xffffffff)
...
Run Code Online (Sandbox Code Playgroud)

我怀疑涉及字节顺序的东西,但我无法理解上面给出的片段.

Sch*_*uki 13

这显然不是由GCC使用,而是由Sparse使用,Sparse是Linux内核使用的C的语义解析器.它记录在Documentation/sparse.txt中.


Bas*_*tch 1

谷歌在这里说按位不再有多大意义了。

  • 这确实意味着什么!如果您正在编写 Linux 设备驱动程序并在大端设备上运行,但控制器以小端方式向您发送消息,则最好确保在适当的位置使用正确的 __le_to_cpu( ) 宏。 (3认同)