相关疑难解决方法(0)

使用匿名结构与使用typedef的命名结构

何时应该使用以下陈述之一?

typedef struct Foo {
    int a;
} Bar;
Run Code Online (Sandbox Code Playgroud)

typedef struct {
    int a;
} Bar;
Run Code Online (Sandbox Code Playgroud)

并使用它

Bar bar1 = { 5 };
Run Code Online (Sandbox Code Playgroud)

我理解第二个是匿名结构但不确定何时应该使用另一个结构.

c

20
推荐指数
4
解决办法
1232
查看次数

在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 ×2