Programming Tips - How can I do an assembler-like NOOP in C/C++ ?

Date: 2010may3 Language: C/C++ Keywords: no-op Q. How can I do an assembler-like NOOP in C/C++ ? A. If you really want to do nothing you can do:
#define NOOP /* do nothing */ ExampleUse() { NOOP }
// Notice there is no trailing semicolon #define NOOP_FUNCTION do { /* do nothing */ } while (false) ExampleUse() { NOOP_FUNCTION(); // This might not get compiled down to nothing }
inline void Noop() { /* do nothing */ } ExampleUse() { Noop(); }
In some environments, in <stdarg.h> you have:
#define va_end(ap) ((void)0) which does very little. ExampleUse() { va_end(ap); }
But sometimes you want a very small time delay. So you can try:
true; ExampleUse() { true; // Very small delay }
In Windows you can do:
Which appears to do very little. It will sleep zero milliseconds and but also give control to another process if it is waiting.