GCC 不一致的编译错误“没有名为 的成员" [英] GCC Inconsistent compilation error 'has no member named '
问题描述
在 C 应用程序中,存在以下代码.
#include #include 类型定义结构{/*!矩阵 ID */内部标识;/*!行数 */int num_rows;/*!列数 */int num_cols;联合{浮动*矩阵;浮动*向量;};} PpetKeviParams;类型定义结构{字符 DB_char;int DB_index;浮动 DB_val;PpetKeviParams outvec;数据库类型;int main(void){DBType *p_DB=(DBType *)malloc(sizeof(DBType));如果(p_DB->outvec.vector == NULL){printf("\t\t\tp_DB->outvec.vector is NULL\n");}如果(p_DB != NULL){免费(p_DB);}返回0;}
上面的代码被编译和执行,作为一个独立的应用程序.
但是,当结构 DBType
用作更大应用程序的一部分时,以下行给出错误,
if (p_DB->outvec.vector == NULL) {
<块引用>
错误:PpetKeviParams"没有名为vector"的成员**
Linux 机器上的 gcc 版本是 4.1.1
在 gcc 4.6.2 机器上编译相同的代码(更大的应用程序).
我找不到问题.有人可以帮忙吗?
上述问题是因为在 GCC 4.1.1 中使用std=c89/c99"的源代码中的未命名联合"问题.禁用std=c89"后,代码将在 GCC 4.1.1 中自行编译.
In an C application, the following code is present.
#include <stdlib.h>
#include <string.h>
typedef struct
{
/*! matrix ID */
int id;
/*! number of rows */
int num_rows;
/*! number of columns */
int num_cols;
union {
float *matrix;
float *vector;
};
} PpetKeviParams;
typedef struct {
char DB_char;
int DB_index;
float DB_val;
PpetKeviParams outvec;
} DBType;
int main(void)
{
DBType *p_DB=(DBType *)malloc( sizeof(DBType));
if (p_DB->outvec.vector == NULL) {
printf("\t\t\tp_DB->outvec.vector is NULL\n");
}
if(p_DB != NULL) {
free(p_DB);
}
return 0;
}
The above code is getting compiled and executed, as an independent application.
But, when the structure DBType
is used as part of a bigger application, the following line gives the error,
if (p_DB->outvec.vector == NULL) {
error: ‘PpetKeviParams’ has no member named ‘vector’**
The gcc version in the Linux machine is 4.1.1
The same code (bigger application) is getting compiled in gcc 4.6.2 machine.
I couldn't find the issue. Can somebody help?
The above issue was because of the issue, 'unnamed union' in source code, in GCC 4.1.1 with 'std=c89 / c99'. After disabling the 'std=c89', the code is getting compiled in GCC 4.1.1, itself.
这篇关于GCC 不一致的编译错误“没有名为 的成员"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!