我尝试用新编译器编译旧代码并得到下一个错误:
error: cannot take the address of an rvalue of type 'int'
这是有 2 行的示例 - 一个编译,另一个给出错误
struct mstct {
int myfield;
int myfield2[5];
int myfield3[5];
};
typedef struct mstct db_data_px;
int foo(int a, int b, int c){
//the next code compiles successfully.
unsigned val1 = ((18 == c) ? ((unsigned) & (((db_data_px *) 0)->myfield)) : ((unsigned) & (((db_data_px *) 0)->myfield3[b]))); //successes
//the next code is failing
unsigned val2 = (unsigned) & ((18 == c) ? (((db_data_px *) 0)->myfield) : (((db_data_px *) 0)->myfield3[b]));
return 0; // failing
}
为什么第一行编译,第二行失败?为什么我需要在两个选择表达式中强制转换 (unsigned) & 并且仅在选择表达式被赋值后才强制转换是不够的?