typedef struct {
char unit1[3]; // unit1 has value ns
char unit2[3]; // unit2 has value ns
char unit3[3]; // unit3 has value ns
} unit;
unit u;
我有一个全局结构,它有 3 个大小为 3 的字符数组,并且其中包含值“ns\0”。 Null 终止,因此大小为 3。
/* This function checks if all has same unit */
int check_conversion_unit() {
if ( (u.unit1[0] == u.unit2[0]) && (u.unit2[0] == u.unit3[0])) // ERROR HERE
return 1;
else
return 0;
}
一些其他函数调用此函数来在计算之前检查所有单元是否具有相同的大小。但是,当我尝试编译此代码时,出现如下错误:
error: subscripted value is neither array nor pointer nor vector
error: subscripted value is neither array nor pointer nor vector
error: subscripted value is neither array nor pointer nor vector
最佳答案
你在这里忘记了)
:
if ( (u.unit1[0] == u.unit2[0]) && (u.unit2[0] == u.unit3[0]) )
// ^
// | that's one
关于c - 指针错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23321854/