正如我所理解的,如果(https://docs.microsoft.com/en-us/cpp/cpp/noalias?view=vs-2019) __declspec(noalias)意味着函数只修改她身体内的内存或通过参数,所以它不修改静态变量,或通过双指针修改内存,对吗?
static int g = 3;
class Test
{
int x;
Test& __declspec(noalias) operator +(const int b) //is noalias correct?
{
x += b;
return *this;
}
void __declspec(noalias) test2(int& x) { //correct here?
x = 3;
}
void __declspec(noalias) test3(int** x) { //not correct here!?
*x = 5;
}
}发布于 2019-09-22 04:52:35
假设如下所示:
extern int x;
extern int bar(void);
int foo(void)
{
if (x)
bar();
return x;
}对bar()一无所知的编译器需要生成允许更改x值的可能性的代码,因此必须在函数调用之前和之后加载x的值。虽然一些系统使用所谓的“链接时间优化”来推迟函数的代码生成,直到分析了它调用的任何函数,以查看它们可能访问的外部对象(如果有的话),但MS使用了一种更简单的方法,即只允许函数原型声明它们不访问调用代码可能想要缓存的任何外部对象。这是一种粗糙的方法,但允许编译器以低成本和容易的方式收获低挂果。
https://stackoverflow.com/questions/57909305
复制相似问题