分享方式:


__ud2

Microsoft 特定的

產生未定義的指令。

語法

void __ud2();

備註

如果您執行未定義的指令,處理器會引發不正確 opcode 例外狀況。

__ud2 函式相當於 UD2 機器指令。 如需詳細資訊,請在 Intel Corporation 網站搜尋檔「Intel Architecture Software Developer's Manual, Volume 2: Instruction Set Reference」 檔。

需求

內建 架構
__ud2 x86、x64

標頭檔 < intrin.h>

END Microsoft 特定的

範例

下列範例會執行未定義的指令,這會引發例外狀況。 然後,例外狀況處理常式會將傳回碼從零變更為一。

// __ud2_intrinsic.cpp
#include <stdio.h>
#include <intrin.h>
#include <excpt.h>
// compile with /EHa

int main() {

// Initialize the return code to 0.
int ret = 0;

// Attempt to execute an undefined instruction.
  printf("Before __ud2(). Return code = %d.\n", ret);
  __try {
  __ud2();
  }

// Catch any exceptions and set the return code to 1.
  __except(EXCEPTION_EXECUTE_HANDLER){
  printf("  In the exception handler.\n");
  ret = 1;
  }

// Report the value of the return code.
  printf("After __ud2().  Return code = %d.\n", ret);
  return ret;
}
Before __ud2(). Return code = 0.
  In the exception handler.
After __ud2().  Return code = 1.

另請參閱

編譯器內建函式