title: Is there a portable way of generating a nop opcode in C/C++?
body: <p>In assembly, there is the <code>nop</code> opcode. Let's say I wanted to have that opcode in the generated assembly using C/C++ syntax alone. Is there any portable way of accomplishing that?</p>
  
  <p>After reading <a href="https://stackoverflow.com/questions/7978620/whats-a-portable-way-to-implement-no-op-statement-in-c">this</a>, I tried to compile <code>(void)0;</code> in the latest MSVC 15.5.2 with no success in generating a nop instruction, with or without optimizations enabled.</p>
  
  <p>Since inline assembly <a href="https://stackoverflow.com/a/13870521/2565020">is not</a> part of the ISO C standard and its support in C++ is <a href="https://stackoverflow.com/a/13870707/2565020">conditional</a>, I would like to avoid that.</p>
  
  <p>In Microsoft Visual Studio, I know I can use the __nop() function defined in the header <code>&lt;intrin.h&gt;</code> as documented <a href="https://docs.microsoft.com/en-us/cpp/intrinsics/nop" rel="nofollow noreferrer">here</a> to successfully create a single <code>nop</code> in the generated assembly.</p>