windows 如何解决warning: 'arr_json_key' initialized and declared 'extern'
时间: 2023-12-20 09:06:52 浏览: 35
在 Windows 平台上,可能会遇到以下警告:
```
warning: 'arr_json_key' initialized and declared 'extern'
```
这是因为在 C 语言中,初始化的变量不能同时声明为 `extern`,因为 `extern` 表示该变量是在其他文件中定义的。在 Windows 平台上,可以通过以下两种方法解决该警告:
1. 将变量声明为 `extern`,在另一个文件中定义该变量并初始化。
在变量声明的地方,使用 `extern` 关键字声明变量,如下所示:
```c
extern const char *arr_json_key[];
```
然后在另一个文件中定义该变量,并进行初始化,如下所示:
```c
const char *arr_json_key[] = {"key1", "key2", "key3"};
```
2. 在变量声明的地方,直接初始化变量。
在变量声明的地方,直接初始化变量,如下所示:
```c
const char *arr_json_key[] = {"key1", "key2", "key3"};
```
这样就不需要使用 `extern` 关键字了。
相关问题
# 一个用来切片的类 def replace_data(data, x, height, weight): # 每height * weight行提取出来作为一个二维数组 arr_reshaped = data.reshape((-1, height * weight, x)) # 将每个二维数组转换成三维数组 arr_3d = [] # 新建一个空的三维数组 # 将提取出的二维数组分别转换并按顺序输入到这个空的三维数组里面 for a in range(arr_reshaped.shape[0]): arr_3d.append(np.reshape(arr_reshaped[a], (height, weight, x))) # 将每个三维数组转换成x * h * w的三维数组 arr_x_h_w = [] for b in range(len(arr_3d)): arr_x_h_w.append(np.transpose(arr_3d[b], (2, 0, 1))) return arr_x_h_w这段代码的功能详解
这个类中的函数 `replace_data()` 的功能是将一个一维数组 `data` 切片成多个二维数组,每个二维数组有 `height` 行和 `weight` 列,并将这些二维数组转换成三维数组,最后将每个三维数组转换成 `x * height * weight` 的三维数组,最终返回一个由这些三维数组组成的列表。
具体实现步骤如下:
1. 将一维数组 `data` 重新排列为一个二维数组,其中每个二维数组有 `height * weight` 行和 `x` 列,即 `arr_reshaped = data.reshape((-1, height * weight, x))`。
2. 将每个二维数组转换成一个三维数组,其中这个三维数组有 `height` 行、`weight` 列和 `x` 个通道。为此,需要遍历每个切片,将其从一维数组形式转换为二维数组形式,然后将其转换为三维数组形式。这个过程通过以下代码实现:
```
arr_3d = [] # 新建一个空的三维数组
for a in range(arr_reshaped.shape[0]):
arr_3d.append(np.reshape(arr_reshaped[a], (height, weight, x)))
```
3. 将每个三维数组转换为 `x * height * weight` 的三维数组,即将每个三维数组的通道维度放到最前面。这个过程通过以下代码实现:
```
arr_x_h_w = []
for b in range(len(arr_3d)):
arr_x_h_w.append(np.transpose(arr_3d[b], (2, 0, 1)))
```
4. 返回由这些 `x * height * weight` 的三维数组组成的列表,即 `arr_x_h_w`。
KeyError: 'arr_1 is not a file in the archive'
This error is typically encountered when trying to access a file or data that is not present in the archive or dataset being used. The error message specifically suggests that the file "arr_1" is missing from the archive.
To resolve this issue, you can try checking the contents of the archive or dataset to ensure that the required file is included. You can also try re-downloading the dataset or archive to ensure that all necessary files are present.
If you are still encountering the error, it may be helpful to review the code or script you are using to access the data and ensure that it is correctly referencing the file or data you are trying to access. Additionally, you can consult documentation or seek assistance from other users or developers who have worked with the same dataset or archive.