我定义了以下静态常量数组:
const int arr[197] = { 55, -63, 12, -17, 121 , ... };
数组永远不会改变。它包含一些适合我的程序的特定数字模式。 该数组用于三个不同的文件:
-
foo1()
在file1.c
-
foo2()
在file2.c
-
foo3()
在file3.c
每次将数组作为参数传递给函数。
因为这个数组的定义很长很广泛,我想创建一个单独的文件来定义和保存那个数组。
应该如何正确地做到这一点?我应该在比方说 arr.h
中定义那个数组吗?然后放#include <arr.h>
里面.c
使用这个数组的文件?
最佳答案
定义 const int arr[197] = ...
在arr.c
.
声明 extern const int arr[197];
在arr.h
只包括arr.h
在arr.c, file1.c, file2.c, file3.c
与 #include "arr.h"
, 不是 #include <arr.h>
几乎像@weno
关于c - 静态数组 - 我应该在哪里定义它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55931105/