未命名的命名空间如何优于static关键字?
我已经被要求修改的驱动程序代码中经常看到静态结构声明.
我试图寻找有关为什么structs声明为静态的信息以及这样做的动机.
你能有人帮我理解这个吗?
在如下所示的类声明中定义时,static enum和enum定义之间的区别是什么?
class Example
{
Example();
~Example();
static enum Items{ desk = 0, chair, monitor };
enum Colors{ red = 0, blue, green };
}
Run Code Online (Sandbox Code Playgroud)
另外,既然我们在一个类中定义类型,我们称之为什么?通过类比,如果我在类中定义变量,我们称之为成员变量.
我搜索了 c 中枚举的静态用法,然后我在这里发布这个主题。我是一名测试人员,我需要通过编写一个简单的程序来测试本地、静态、全局范围的枚举数据类型。
一个简单的静态变量可以很容易地测试,同样我需要测试静态枚举数据类型。
我写了一个简单的代码。需要你们的帮助。
#include<stdio.h>
enum day {sun=1,mon,tue,wed,thur,fri,sat};
static enum direction {UP,DOWN,RIGHT,LEFT};
int static_enum()
{
static enum direction dir = UP;
printf("dir = %d\n",dir);
dir++;
}
int main()
{
printf("\nsun = %d mon = %d tue = %d wed = %d thurs = %d fri = %d sat = %d\n",sun,mon,tue,wed,thur,fri,sat);
enum day fri = 25;
// now friday gets modified from 21 to 25 becasue we have re-assigned the value
printf("\nfri = %d\n",fri);
// now saturday …Run Code Online (Sandbox Code Playgroud)