在条件语句中使用“?”表示“表达式不可分配” (在C中)

我刚遇到带'?'的条件语句运算符,无法弄清楚为什么“ exit = 1”语句不可分配。我试过切换变量的类型,并加上括号。

//all the normal stuff is included

unsigned int exit = 0;

      (strcmp(arg2,"%rax") == 0)? r2 = RAX :
      (strcmp(arg2,"%rcx") == 0)? r2 = RCX :
      (strcmp(arg2,"%rdx") == 0)? r2 = RDX :
      (strcmp(arg2,"%rbx") == 0)? r2 = RBX :
      (strcmp(arg2,"%rsp") == 0)? r2 = RSP :
      (strcmp(arg2,"%rbp") == 0)? r2 = RBP :
      (strcmp(arg2,"%rsi") == 0)? r2 = RSI :
      (strcmp(arg2,"%rdi") == 0)? r2 = RDI :
      (strcmp(arg2,"%r8") == 0)? r2 = R8 :
      (strcmp(arg2,"%r9") == 0)? r2 = R9 :
      (strcmp(arg2,"%r10") == 0)? r2 = R10 :
      (strcmp(arg2,"%r11") == 0)? r2 = R11 :
      (strcmp(arg2,"%r12") == 0)? r2 = R12 :
      (strcmp(arg2,"%r13") == 0)? r2 = R13 :
      (strcmp(arg2,"%r14") == 0)? r2 = R14 :
      (strcmp(arg2,"%r15") == 0)? r2 = NO_REG : exit = 1; //Equivalent to "true" in the if() statement

错误显示在最后一行“ exit = 1”

mystiquec 回答:在条件语句中使用“?”表示“表达式不可分配” (在C中)

分配的优先级低于条件的优先级。因此,"dependencies": { "@react-native-community/async-storage": "^1.6.2","link": "^0.1.5","react": "16.9.0","react-native": "^0.61.4","react-native-gesture-handler": "^1.5.0","react-native-reanimated": "^1.4.0","react-native-screens": "^2.0.0-alpha.7","react-native-vector-icons": "^6.6.0","react-navigation": "^4.0.10","react-navigation-redux-helpers": "^4.0.1","react-navigation-stack": "^1.10.3","react-redux": "^7.1.1","redux": "^4.0.4","redux-persist": "^6.0.0" } 的值为a ? b : c = 0,其中(a ? b : c) = 0不是有效的左值。

立即解决方案:使用括号强制进行所需的解析:(a ? b : c)

更好的解决方案:将其重写为更好的东西,例如在成对的数组上循环-或至少是a ? b : (c = 0) / if结构,这将使优先级成为问题。 / p>

本文链接:https://www.f2er.com/3162332.html

大家都在问