相关疑难解决方法(0)

822
推荐指数
10
解决办法
35万
查看次数

typedef struct vs struct definitions

我是C编程的初学者,但我想知道typedef在定义结构时使用与使用结构之间有什么区别typedef.在我看来,实际上没有区别,他们实现了同样的目标.

struct myStruct{
    int one;
    int two;
};
Run Code Online (Sandbox Code Playgroud)

typedef struct{
    int one;
    int two;
}myStruct;
Run Code Online (Sandbox Code Playgroud)

c struct typedef

763
推荐指数
10
解决办法
66万
查看次数

是否可以转发声明静态数组

我需要将静态数组放入.cpp文件中.此数组仅用于此.cpp,因此我想将其声明为静态.数组定义非常大,所以我自然要转发声明它.

static int bigIntArray[5000];

/* other code using bitIntArray */

static int bigIntArray[5000] = {
  0x00, 0x9900, 0xffee,
  ...
};
Run Code Online (Sandbox Code Playgroud)

VC 9.0给出错误:错误C2086:'int bigIntArray [5000]':重新定义

如果我将'static'改为'extern',问题就会消失,但我不喜欢这个解决方案.

为什么我不能转发声明一个静态变量?这是C++标准所要求的吗?

c++

19
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×2

c++ ×1

c++-faq ×1

declaration ×1

definition ×1

struct ×1

terminology ×1

typedef ×1