49彩票集团首页-49彩票集团官网|官网首页

49彩票集团让大家拥有最好的账号使用功能,49彩票集团是为大家带来更加方便的使用途径,是因为在49彩票集团娱乐的玩家们越来越多,发展成为最受欢迎的网上体育娱乐公司。

概念的叙述符表为三个组织体数组,{}只可以

2019-11-11 作者:计算机网络   |   浏览(180)

c结构体初始化问题,c结构初始化

结构体中的数组的初始化问题 我的代码

C/C++ code
#include <stdio.h>
#include <stdlib.h>
struct a
    {
    int length;
    int c[5];
    }b;
int main()
{ 
    b.c={1,2,3,4,5};

 }

 

调试时编译器报错,求指点

------解决方案-------------------- 你那个结构体属于全局变量,在进入main之前就已经分配空间了。

{}只能用来来初始化,只有在定义的时候能用。给数组赋值是不能用{}的。

你的代码应该改成这样

C/C++ code
#include <stdio.h>
#include <stdlib.h>
struct a
    {
    int length;
    int c[5];
    }b={0,1,2,3,4,5};//0是初始化给length的,后面5个是给数组的,要按顺序。
int main()
{ 

}
------解决方案--------------------

C/C++ code
#include <stdio.h>
#include <stdlib.h>
struct a
    {
    int length;
    int c[5];
    }b;
int main()
{ 
int i;
for(i=0;i<5;i++)
    b.c[i]=i+1;  
 }

 

------解决方案-------------------- 参考普通的数组 {1,2,3,4,5}这样的初始化只能在定义的时候

分配空间只能逐个赋值或者用循环赋值

字符组数的初始化同上。。

结构体中的数组的初始化问题 我的代码 C/C++ code#include stdio.h #include stdlib.h struct a { int length; int c[49彩票集团, 5 ]; }b...

1.中断描述符表的定义(arch/x86/kernel/traps.c)

1 gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;

定义的描述符表为一个结构体数组,数组元素类型为gate_desc,大小为8B。NR_VECTORS宏为256,即描述符表大小为256*8B。

 

2.idt_descr变量的定义(arch/x86/kernel/head_32.S)

1 idt_descr:
2     .word IDT_ENTRIES*8-1        # idt contains 256 entries
3     .long idt_table
4 
5 # boot GDT descriptor (later on used by CPU#0):
6     .word 0                # 32 bit align gdt_desc.address

这是内核定义的一个全局变量,存放有中断描述符表的大小和首地址。该变量将存放在idtr寄存器中。

 

3.中断描述符初步的初始化(arch/x86/kernel/head_32.S)

 1 __INIT
 2 setup_once:
 3     /*
 4      * Set up a idt with 256 entries pointing to ignore_int,
 5      * interrupt gates. It doesn't actually load idt - that needs
 6      * to be done on each CPU. Interrupts are enabled elsewhere,
 7      * when we can be relatively sure everything is ok.
 8      */
 9 
10     movl $idt_table,%edi
11     movl $early_idt_handlers,%eax12     movl $NUM_EXCEPTION_VECTORS,%ecx
13 1:
14     movl %eax,(%edi)
15     movl %eax,4(%edi)
16     /* interrupt gate, dpl=0, present */
17     movl $(0x8E000000 + __KERNEL_CS),2(%edi)
18     addl $9,%eax
19     addl $8,%edi
20     loop 1b
21 
22     movl $256 - NUM_EXCEPTION_VECTORS,%ecx
23     movl $ignore_int,%edx
24     movl $(__KERNEL_CS << 16),%eax
25     movw %dx,%ax        /* selector = 0x0010 = cs */
26     movw $0x8E00,%dx    /* interrupt gate - dpl=0, present */
27 2:
28     movl %eax,(%edi)
29     movl %edx,4(%edi)
30     addl $8,%edi
31     loop 2b
32         ...
33         ...

这段代码是对中断描述符表的初步初始化,14-20行是对前32个中断描述符进行初始化,让所有描述符指向early_idt_handlers处理函数。22-31行是对后256-32=224个中断描述符进行初始化,使之指向ignore_int处理函数。省略号以后是对GDT描述符表的初始化,这里不予讨论。

 

4.中断描述符表最终的初始化(arch/x86/kernel/traps.c)

 1 void __init trap_init(void)
 2 {
 3     int i;
 4 
 5 #ifdef CONFIG_EISA
 6     void __iomem *p = early_ioremap(0x0FFFD9, 4);
 7 
 8     if (readl(p) == 'E' + ('I'<<8) + ('S'<<16) + ('A'<<24))
 9         EISA_bus = 1;
10     early_iounmap(p, 4);
11 #endif
12 
13     set_intr_gate(X86_TRAP_DE, divide_error);
14     set_intr_gate_ist(X86_TRAP_NMI, &nmi, NMI_STACK);
15     /* int4 can be called from all */
16     set_system_intr_gate(X86_TRAP_OF, &overflow);
17     set_intr_gate(X86_TRAP_BR, bounds);
18     set_intr_gate(X86_TRAP_UD, invalid_op);
19     set_intr_gate(X86_TRAP_NM, device_not_available);
20 #ifdef CONFIG_X86_32
21     set_task_gate(X86_TRAP_DF, GDT_ENTRY_DOUBLEFAULT_TSS);
22 #else
23     set_intr_gate_ist(X86_TRAP_DF, &double_fault, DOUBLEFAULT_STACK);
24 #endif
25     set_intr_gate(X86_TRAP_OLD_MF, coprocessor_segment_overrun);
26     set_intr_gate(X86_TRAP_TS, invalid_TSS);
27     set_intr_gate(X86_TRAP_NP, segment_not_present);
28     set_intr_gate_ist(X86_TRAP_SS, &stack_segment, STACKFAULT_STACK);
29     set_intr_gate(X86_TRAP_GP, general_protection);
30     set_intr_gate(X86_TRAP_SPURIOUS, spurious_interrupt_bug);
31     set_intr_gate(X86_TRAP_MF, coprocessor_error);
32     set_intr_gate(X86_TRAP_AC, alignment_check);
33 #ifdef CONFIG_X86_MCE
34     set_intr_gate_ist(X86_TRAP_MC, &machine_check, MCE_STACK);
35 #endif
36     set_intr_gate(X86_TRAP_XF, simd_coprocessor_error);
37 
38     /* Reserve all the builtin and the syscall vector: */
39     for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++)
40         set_bit(i, used_vectors);
41 
42 #ifdef CONFIG_IA32_EMULATION
43     set_system_intr_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
44     set_bit(IA32_SYSCALL_VECTOR, used_vectors);
45 #endif
46 
47 #ifdef CONFIG_X86_32
48     set_system_trap_gate(SYSCALL_VECTOR, &system_call);FIRST_EXTERNAL_VECTOR
49     set_bit(SYSCALL_VECTOR, used_vectors);
50 #endif
51 
52     /*
53      * Set the IDT descriptor to a fixed read-only location, so that the
54      * "sidt" instruction will not leak the location of the kernel, and
55      * to defend the IDT against arbitrary memory write vulnerabilities.
56      * It will be reloaded in cpu_init() */
57     __set_fixmap(FIX_RO_IDT, __pa_symbol(idt_table), PAGE_KERNEL_RO);
58     idt_descr.address = fix_to_virt(FIX_RO_IDT);
59 
60     /*
61      * Should be a barrier for any external CPU state:
62      */
63     cpu_init();
64 
65     x86_init.irqs.trap_init();
66 
67 #ifdef CONFIG_X86_64
68     memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16);
69     set_nmi_gate(X86_TRAP_DB, &debug);
70     set_nmi_gate(X86_TRAP_BP, &int3);
71 #endif
72 }

该函数对中断描述表的进行了部分初始化,13-36行对系统已分配的异常和非屏蔽中断进行初始化,中断向量号为0-19。接着,39-40行在中断位图表中对已初始化的中断所对应的位进行标记。接着,43和48行又出始化了两个中断,一个是系统中断门,中断向量号为0x80,一个是系统陷阱门,中断向量号为2。

在该函数中,大家可以看出,对中断进行初始化的函数有如下几个:

1 set_intr_gate()
2 set_system_intr_gate()
3 set_system_trap_gate()
4 set_task_gate()

这几个函数也在arch/x86/kernel/traps.c中定义。分别是对中断门,系统中断门,系统陷阱门,任务门描述符的初始化。进一步深入可发现,这几个函数都调用了如下的函数:

 1 static inline void _set_gate(int gate, unsigned type, void *addr,
 2                  unsigned dpl, unsigned ist, unsigned seg)
 3 {
 4     gate_desc s;
 5 
 6     pack_gate(&s, type, (unsigned long)addr, dpl, ist, seg);
 7     /*
 8      * does not need to be atomic because it is only done once at
 9      * setup time
10      */
11     write_idt_entry(idt_table, gate, &s);
12     write_trace_idt_entry(gate, &s);
13 }

本文由49彩票集团发布于计算机网络,转载请注明出处:概念的叙述符表为三个组织体数组,{}只可以

关键词: