Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C++
C/C++ Languages
Compiler Intrinsics
 __ud2
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual C++ Language Reference
__ud2

Microsoft Specific

This topic is new for Visual Studio 2005 SP1.

Generates an undefined instruction.

void __ud2();

The processor raises an invalid opcode exception if you execute an undefined instruction.

The __ud2 function is equivalent to the UD2 machine instruction, and is available only in kernel mode. For more information, search for the document, "Intel Architecture Software Developer's Manual, Volume 2: Instruction Set Reference," at the Intel Corporation site.

Intrinsic

Architecture

__ud2

x86, x64

Header file <intrin.h>

The following example executes an undefined instruction, which raises an exception. The exception handler then changes the return code from zero to one.

// __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.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker