相关疑难解决方法(0)

在C++标识符中使用下划线有哪些规则?

在C++中通常用某种前缀命名成员变量来表示它们是成员变量而不是局部变量或参数.如果你来自MFC背景,你可能会使用m_foo.我myFoo偶尔也见过.

C#(或者可能只是.NET)似乎建议只使用下划线,如_foo.这是否允许C++标准?

c++ standards naming-conventions c++-faq

906
推荐指数
4
解决办法
24万
查看次数

在C程序中使用_和__

我正在读K&R书.我读:

...仅供标准库函数使用的名称,_因此它们不太可能与用户程序中的名称冲突...

这究竟意味着什么,请解释真实简单实用的方法.

我的理解是:

如果我想使用math.h中定义的sqrt那么

#include <math.h>
#define sqrt(x) x*x*x

main() 
{ 
int x=4; 
_sqrt(x); // That is from the header file math.h
sqrt(x); // my own defined macro 
/*or its the reverse way _sqrt for my own defined macro so it won't collide with original sqrt i.e. without _ for sqrt from math.h */ 
return 0;
}
Run Code Online (Sandbox Code Playgroud)

现在,我使用了在stackoverflow上读取代码__.sys/syscall.h在Windows中不存在,所以我们必须使用

#if __linux 
#include <sys/syscall.h>
#elif defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif
Run Code Online (Sandbox Code Playgroud)

确切__使用的地方和b/w __&的区别_ …

c

12
推荐指数
2
解决办法
3万
查看次数

标签 统计

c ×1

c++ ×1

c++-faq ×1

naming-conventions ×1

standards ×1