我需要做什么: 修改 Linux 内核代码(从 kernel.org 下载的 3.13.6)。查找调用 kvm_vmx_exit_handler 函数的次数。
我正在尝试做的事情: 在文件 'x86.h' 中声明一个数组
extern unsigned long int my_count_s[40];
包含在“vmx.c”文件中的 x86.h 文件
#include "x86.h"
现在,我正在尝试将数组中的一个元素初始化为文件“vmx.c”中的值 0。
my_count_s[1] = 0;
每次调用 kvm_exit_handler 函数时,我都会递增它。我将了解发生某些事情时 kvm 退出的次数,以及调用特定退出处理函数的次数。我将为每个 exithandler 函数使用数组的单个元素。
我遇到的错误:
arch/x86/kvm/vmx.c:58:1: warning: data definition has no type or storage class [enabled by default]
arch/x86/kvm/vmx.c:58:1: error: type defaults to ‘int’ in declaration of ‘my_count_s’ [-Werror=implicit-int]
arch/x86/kvm/vmx.c:58:1: error: conflicting types for ‘my_count_s’
arch/x86/kvm/x86.h:8:26: note: previous declaration of ‘my_count_s’ was here
arch/x86/kvm/vmx.c:58:1: error: invalid initializer
我的理解: 我已将 my_count_s[40] 的数据类型声明为 unsigned long int,但为什么默认为“int”? 即使它是默认的 ti 数据类型“int”,为什么 my_count_s[1] = 0 行会出现初始化错误; ?
注意: 1. vmx.c 中的第 58 行是“my_count_s[1]=0;” 2. 如果我只通过声明数组来编译内核,它工作正常,但在我尝试为数组中的元素赋值时弹出错误。
最佳答案
语句,包括赋值必须在函数内部。我敢打赌你在函数之外。
编译器感到困惑,因为 =
只能出现在声明和语句中,并且由于它在函数外部,所以您的行被解析为声明。那是行不通的;类型在哪里?
关于c - 为数组元素赋值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23530169/