我正在阅读有关《毁灭战士3》源代码的代码质量的博客文章,但我被困在一段我无法理解的C++代码中。我应该说我不是C++程序员。
令人反感的代码如下:
Sys_StartAsyncThread(){ // The next look runs is a separate thread.
while ( 1 ){
usleep( 16666 ); // Run at 60Hz
common->Async(); // Do the job
Sys_TriggerEvent( TRIGGER_EVENT_ONE ); // Unlock other thread waiting for inputs
pthread_testcancel(); // Check if we have been cancelled by the main thread (on shutdown).
}
}
(摘自http://fabiensanglard.net/doom3/index.php,在“展开循环”主题下)
在我看来,这是作为参数传递给
Sys_StartAsyncThread()
的返回值的闭包-但据我所知,这在C++中是不可能的,而且Sys_StartAsyncThread()
是void类型的,所以这是怎么回事?Sys_StartAsyncThread()
的定义可以在here中找到。 最佳答案
看起来像错字。根据here,在Sys_StartAsyncThread();
之后应该有一个分号。