我的意思是我们可以将C中的函数声明为const
void fun(int iVar) const;
int g_var = 1;
void fun(int iVar)
{
//do some thing
g_var = iVar;
}
Run Code Online (Sandbox Code Playgroud)
unw*_*ind 14
不在标准C中,因为没有类或对象(如"类实例,即具有相关函数的数据集合"),该函数没有任何const
"反对".
从理论上讲,这种符号可能意味着"这个函数没有全局可见的副作用,它是输入参数的纯函数"但是没有.
作为扩展,GNU GCC编译器支持将函数声明为:const
或者pure
:
int square(int) __attribute__((pure));
Run Code Online (Sandbox Code Playgroud)
该__attribute((pure))
部分是GCC特定的.
归档时间: |
|
查看次数: |
488 次 |
最近记录: |