额,没睡醒
while (RemoveFirst());
多了个分号
可是我只F11了一次呀,难道编译器优化掉了吗?
while (RemoveFirst());
多了个分号
可是我只F11了一次呀,难道编译器优化掉了吗?
<code class="lang-c">typedef struct _KEYBOARD_INPUT_DATA { // // Unit number. E.g., for \Device\KeyboardPort0 the unit is '0', // for \Device\KeyboardPort1 the unit is '1', and so on. // USHORT UnitId; // // The "make" scan code (key depression). // char MakeCode; // // The flags field indicates a "break" (key release) and other // miscellaneous scan code information defined below. // USHORT Flags; USHORT Reserved; // // Device-specific additional information for the event. // ULONG ExtraInformation; } KEYBOARD_INPUT_DATA, *PKEYBOARD_INPUT_DATA; typedef struct _WriteDataStruct { UINT8 Command; UINT8 Data[]; }WriteData, *PWriteData; typedef void(__stdcall*PUserRing0Fun)(); //C++函数指针 void UserFun() { printf("被调用了!!!!!!!!!!!!"); } typedef struct _ListData { KEYBOARD_INPUT_DATA DATA; struct _ListData *Next; }ListData, *PListData; volatile PListData PldFirst; volatile PListData *PPldLast; //PListData *PldCurrent; void Add(PListData ld) { (*PPldLast) = (PListData)malloc(sizeof(ListData)); (*PPldLast)->DATA.ExtraInformation = ld->DATA.ExtraInformation; (*PPldLast)->DATA.Flags = ld->DATA.Flags; (*PPldLast)->DATA.MakeCode = ld->DATA.MakeCode; (*PPldLast)->DATA.Reserved = ld->DATA.Reserved; (*PPldLast)->DATA.UnitId = ld->DATA.UnitId; (*PPldLast)->Next = nullptr; PPldLast = &((*PPldLast)->Next); } void Init() { PldFirst = nullptr; PPldLast = &PldFirst; } volatile PListData ldNext; BOOL RemoveFirst(void) { if (PldFirst != nullptr) { ldNext = (PldFirst->Next); if (ldNext != nullptr) { free(PldFirst); PldFirst = ldNext; return TRUE; } else { free(PldFirst); PldFirst = nullptr; PPldLast = &PldFirst; return FALSE; } } else { return FALSE; } } int main() { Init(); ListData ld = {0}; for (size_t i = 0; i < 3; i++) { ld.DATA.MakeCode = getchar(); Add(&ld); } std::cout << PldFirst->DATA.MakeCode; RemoveFirst(); //while (RemoveFirst()); //注意这里,如果RemoveFirst()在while括号中的话,执行后 PldFirst指向0 { std::cout << PldFirst->DATA.MakeCode; } return 0; }</code>
<code class="lang-cpp">std::cout << PldFirst->DATA.MakeCode; while (RemoveFirst()); { std::cout << PldFirst->DATA.MakeCode; //PldFirst指向0 } return 0;</code>
<code class="lang-cpp">std::cout << PldFirst->DATA.MakeCode; RemoveFirst(); std::cout << PldFirst->DATA.MakeCode; //PldFirst指针正常 return 0;</code>
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |
200字以内,仅用于支线交流,主线讨论请采用回复功能。