我想提出一個鍵盤驅動程序我的OSDev OS和我在我的kbd.c一個問題:錯誤:可變大小的對象可能未被初始化?
kbd.c: In function 'scancoderec':
kbd.c:56:2: error: variable-sized object may not be initialized
register int (ScanCode[strlen(ValEAX)-8]) = 0x00; /* Remove last 8 bits from the value we gathered from EAX to get AH and make that the scancode. */
這裏是包含的代碼失敗行的功能:
int scancoderec() {
__asm__ volatile("movl $0, %eax"); /* Moving 00 to EAX. */
__asm__ volatile("int $0x16 "); /*int 0x16 */
register int ValEAX asm("eax"); /* Let's get eax */
register int (ScanCode[strlen(ValEAX)-8]) = 0x00; /* Remove last 8 bits from the value we gathered from EAX to get AH and make that the scancode. */
}
爲什麼這是否發生?
編輯:我仍然有這個「ax」是未定義的,這次,在另一個函數中。
kbd.c:65:27: error: 'ax' undeclared (first use in this function)
register int Key = kbdus[ax];
掃描碼功能和信息getKey功能的代碼:
unsigned short scancodeget()
{
unsigned char ax = 0; /* int 0x16, AH=0 is get keystroke */
__asm__ __volatile__ ("int $0x16\n\t"
: "+a"(ax));
ax = ax >> 8; /* Shift top 8 bits of ax to lower 8 bits */
/* ax now is the scancode returned by BIOS */
return (unsigned short)ax; /* Return the lower 8 bits */
}
int getkey() { /*This could be used as a keyboard driver. */
scancoderec(); /*Get our scancode! */
int Key = kbdus[ax]; /*Use our kbdus array which i copied from a website since i seriously don't want to make an gigantic array */
}
編譯器認爲你正在聲明一個名爲'ScanCode'的數組。坦率地說,我不知道你要在代碼中做什麼。 – user3386109
評論說:「從值中刪除最後8位...」 - >看起來像「刪除最後8個字節...」 – chux
嗯,如果'strlen(ValEAX)<= 8',代碼肯定會有麻煩。 – chux