Tag: 属性

init-declarator-list和GNU GCC属性语法

我正在改进一个内部C语言野牛/基于flex的解析器,其中包括引入正确的__ attribute__支持。 因为我找不到任何描述GNU GCC __ attribute__想法的官方BNF风格的语法(除了http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html文档),我从C中提取点点滴滴通过网络找到的各种实现中的++ x11标准和注释。 我几乎完成了它(至少在解析上面引用的GCC文档中包含的示例时),但是一个特定的例子令我头疼,外部资源没有提示解决方案。 示例如下: __attribute__((noreturn)) void d0 (void), __attribute__((format(printf, 1, 2))) d1 (const char *, …), d2 (void); 附件说明: 属性说明符列表可以使用单个说明符和限定符列表,在多个标识符的声明中以逗号分隔的声明符列表中的声明符(不是第一个)之前出现。 此类属性说明符仅适用于它们出现在其声明符之前的标识符。 因此,引导我解决这个问题: init-declarator-list: init-declarator init-declarator-list , attribute-specifier-seq[opt] init-declarator 我知道它有效,但如果这是解决上述案例的正确方法,我想寻求validation/支持。 谢谢, 沃伊切赫 编辑:这个链接(虽然有点过时)给出了一个像我一样的解决方案: http : //plg.uwaterloo.ca/~cforall/gcc.y奇怪的是,我之前没有偶然发现它,只是在我做的时候搜索__ extension__关键字。

GCC:__ attribute __((malloc))

引用海湾合作委员会文件 (强调我的): malloc属性用于告诉编译器可以将函数视为其返回的任何非NULL指针在函数返回时不能将任何其他指针作为别名,并且内存具有未定义的内容 。 这通常会改善优化。 具有此属性的标准函数包括malloc和calloc 。 类似realloc的函数没有此属性,因为指向的内存没有未定义的内容。 我有以下代码: struct buffer { size_t alloc; // Allocated memory in bytes size_t size; // Actual data size in bytes char data[]; // Flexible array member }; #define ARRAY_SIZE buffer *buffer_new(void) __attribute__((malloc)) { struct buffer *ret; ret = malloc(sizeof(struct buffer) + ARRAY_SIZE); if (!ret) fatal(E_OUT_OF_MEMORY); ret->alloc = ARRAY_SIZE; […]

GCC按位属性

GCC的__attribute__(bitwise)是什么意思? GCC-4.6的信息页面中未提及该属性。 我在文件open-iscsi-2.0.871/include/iscsi_proto.h中open-iscsi-2.0.871/include/iscsi_proto.h进行了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 */ […]

__attribute __((packed))对嵌套结构数组的影响?

问题 我正在努力通过网络将原始结构发送到另一端的已知程序,但不得不担心用于对齐结构的静默引入的内存(其他问题,如字节顺序被覆盖)。 我正在使用的是: typedef struct __attribute__((packed)) { uint16_t field1; uint16_t field2; uint16_t field3; } packed_1_s; typedef struct __attribute__((packed)) { uint16_t fieldA; uint16_t fieldB; packed_1_s structArray[10]; } packed_2_s; typedef struct __attribute__((packed)) { uint16_t fieldX; packed_2_s fieldY; uint8_t arrayZ[20]; } data_s; 我理解通常,packed_1_s结构可以/将为结构的每个实例分配额外的空间,以将其填充到编译器的优选大小(取决于它所构建的硬件),并且有利的大小可以是2个字节的任何位置到64个字节(最近)。 通常情况下,如果我在packed_2_s中有一个packed_1_s的实例就没有问题,但是当我尝试将元素放入数组时,我会理解它们存在一些差异。 试图解决方案 gcc文档似乎建议通过简单地在packed_2_s定义中包含packed属性,即使它们是数组,这些字段也将尽可能紧密地包装,并且不会为packed_2_s结构添加空间以对齐元素数组。 关于align()属性的文档虽然表明数组的处理方式与其他字段不同,但需要在字段上直接设置align / packed属性,以便修改添加的额外间距以匹配指定的对齐(或缺少对齐)。 我尝试在structArray字段上设置packed属性,当它不起作用时,通过在上面的代码中设置arrayZ上的packed属性进行测试: packed_1_s structArray[10] __attribute__((packed)); uint8_t arrayZ[20] __attribute__((packed)); 两次尝试都给了我一个编译器警告,在这个上下文中没有理解packed属性并且会被跳过(我用“-Wall”构建的好东西)。 我希望绕过这个问题的方法是使用属性align(1),指示1字节的所需对齐,这与packed属性相当,但是文档说align()属性只能增加对齐和打包应该用于减少对齐。 […]

C(或C ++)的属性文件库

标题是不言自明的:有没有人知道C的(好)属性文件阅读器库,如果没有,C ++? [编辑:具体来说,我想要一个处理Java中使用的.properties文件格式的库: http : //en.wikipedia.org/wiki/.properties]

FILE类型的对象的属性是什么

FILE对象通常是通过调用fopen或tmpfile创建的,它们都返回对这些对象之一的引用。 Struct名为FILE的属性是什么,还是依赖于平台?

GCC __attribute __((模式(XX))实际上做了什么?

这源于今天早些时候关于bignum库和gcc特定的C语言攻击主题的问题。 具体来说,使用了这两个声明: typedef unsigned int dword_t __attribute__((mode(DI))); 在32位系统和 typedef unsigned int dword_t __attribute__((mode(TI))); 在64位系统上。 我假设这是对C语言的扩展,没有办法实现它在当前(C99)标准中实现的任何目标。 所以我的问题很简单:这个假设是否正确? 这些陈述对底层内存有何影响? 我认为结果是我在32位系统中使用2*sizeof(uint32_t) ,在64位系统中使用2*sizeof(uint64_t) ,我是否正确?

GNU C中的__attribute __((const))vs __attribute __((pure))

GNU C中__attribute__((const))和__attribute__((pure))什么区别? __attribute__((const)) int f() { /* … */ return 4; } VS __attribute__((pure)) int f() { /* … */ return 4; }