C结构还是功能?

我试图了解linux中的kvm代码并遇到了tjis:

    static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = {
[SVM_EXIT_READ_CR0]         = cr_interception,
[SVM_EXIT_READ_CR3]         = cr_interception,
[SVM_EXIT_READ_CR4]         = cr_interception,
[SVM_EXIT_READ_CR8]         = cr_interception,
[SVM_EXIT_CR0_SEL_WRITE]        = emulate_on_interception,
[SVM_EXIT_WRITE_CR0]            = cr_interception,
[SVM_EXIT_WRITE_CR3]            = cr_interception,
[SVM_EXIT_WRITE_CR4]            = cr_interception,
[SVM_EXIT_WRITE_CR8]            = cr8_write_interception,
[SVM_EXIT_READ_DR0]         = dr_interception,
[SVM_EXIT_READ_DR1]         = dr_interception,
[SVM_EXIT_READ_DR2]         = dr_interception,
[SVM_EXIT_READ_DR3]         = dr_interception,
[SVM_EXIT_READ_DR4]         = dr_interception,
[SVM_EXIT_READ_DR5]         = dr_interception,
[SVM_EXIT_READ_DR6]         = dr_interception,
[SVM_EXIT_READ_DR7]         = dr_interception,
[SVM_EXIT_WRITE_DR0]            = dr_interception,
[SVM_EXIT_WRITE_DR1]            = dr_interception,
[SVM_EXIT_WRITE_DR2]            = dr_interception,
[SVM_EXIT_WRITE_DR3]            = dr_interception,
[SVM_EXIT_WRITE_DR4]            = dr_interception,
[SVM_EXIT_WRITE_DR5]            = dr_interception,
[SVM_EXIT_WRITE_DR6]            = dr_interception,
[SVM_EXIT_WRITE_DR7]            = dr_interception,
[SVM_EXIT_EXCP_BASE + DB_VECTOR]    = db_interception,
[SVM_EXIT_EXCP_BASE + BP_VECTOR]    = bp_interception,
[SVM_EXIT_EXCP_BASE + UD_VECTOR]    = ud_interception,
[SVM_EXIT_EXCP_BASE + PF_VECTOR]    = pf_interception,
[SVM_EXIT_EXCP_BASE + NM_VECTOR]    = nm_interception,
[SVM_EXIT_EXCP_BASE + MC_VECTOR]    = mc_interception,
[SVM_EXIT_INTR]             = intr_interception,
[SVM_EXIT_NMI]              = nmi_interception,
[SVM_EXIT_SMI]              = nop_on_interception,
[SVM_EXIT_INIT]             = nop_on_interception,
[SVM_EXIT_VINTR]            = interrupt_window_interception,
[SVM_EXIT_RDPMC]            = rdpmc_interception,
[SVM_EXIT_CPUID]            = cpuid_interception,
[SVM_EXIT_IRET]                         = iret_interception,
[SVM_EXIT_INVD]                         = emulate_on_interception,
[SVM_EXIT_PAUSE]            = pause_interception,
[SVM_EXIT_HLT]              = halt_interception,
[SVM_EXIT_INVLPG]           = invlpg_interception,
[SVM_EXIT_INVLPGA]          = invlpga_interception,
[SVM_EXIT_IOIO]             = io_interception,
[SVM_EXIT_MSR]              = msr_interception,
[SVM_EXIT_TASK_SWITCH]          = task_switch_interception,
[SVM_EXIT_SHUTDOWN]         = shutdown_interception,
[SVM_EXIT_VMRUN]            = vmrun_interception,
[SVM_EXIT_VMMCALL]          = vmmcall_interception,
[SVM_EXIT_VMLOAD]           = vmload_interception,
[SVM_EXIT_VMSAVE]           = vmsave_interception,
[SVM_EXIT_STGI]             = stgi_interception,
[SVM_EXIT_CLGI]             = clgi_interception,
[SVM_EXIT_SKINIT]           = skinit_interception,
[SVM_EXIT_WBINVD]                       = emulate_on_interception,
[SVM_EXIT_MONITOR]          = invalid_op_interception,
[SVM_EXIT_MWAIT]            = invalid_op_interception,
[SVM_EXIT_XSETBV]           = xsetbv_interception,
[SVM_EXIT_NPF]              = pf_interception,

};

我非常精通C,但是在任何地方都没有遇到这个问题,如果这是一个功能或结构声明或其他原因,我真的很困惑.任何帮助都会很乐意接受.

最佳答案
这是一个函数指针数组.

它使用指定的初始化程序初始化.

编辑:声明可以理解如下 –

将svm_exit_handlers声明为const指针的静态数组,该指针指向struct vcpu_svm并返回int的函数

(您可能会发现http://www.cdecl.org对解析困难的C声明有所帮助.)

在更通俗的英语中,这意味着这是一个函数指针数组.指向的函数的形式为int foo(struct vcpu_svm * svm).

编辑:指定的初始化程序也可能有些混乱.见http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

转载注明原文:C结构还是功能? - 代码日志