这是C代码。
int main() {
int i = 10, *p = &i;
printf("%ld", p - (int *) NULL);
}
Run Code Online (Sandbox Code Playgroud)
对于指针算术部分,'gcc'和'clang'均在其汇编输出中生成'sar rax,2'指令。有人可以解释这种情况下的指针算术与算术右移有何关系。
gcc v10.2.0,-std=c++11
我不想使用“std::to_string()”将双精度值转换为文字字符串。试图实现将整数添加到字符串但使用双精度值的类似效果。
预期输出:“abcdA”
string s { "abcd" };
double d { 65.1 };
// s = s + d; // Error. no match for ‘operator+’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} and ‘double’)
s += d;
Run Code Online (Sandbox Code Playgroud)
'string' 类的 'operator+' 和 'operator+=' 方法都有一个接受 'char' 参数的版本,但只有 'operator+=' 方法似乎接收隐式转换的值并且不会产生错误。
为什么编译器选择将转换后的值传递给另一个。