Nothing (without text) is a valid replacement text for a macro. It will simply be deleted (more precisely, replaced by nothing) by the preprocessor.
There are several reasons why you will use something like this. One of them is just to use the macro in #ifdef and similar constructors.
Another is conditional compilation. Typical use cases are public APIs and DLL exports. On Windows, you need to mark a function exported from a DLL (when creating a DLL) or imported from a DLL (when linking to a DLL). ELF systems do not require such declarations. Therefore, in the headers of the public library, you often see the following code:
#ifdef _WIN32 #ifdef BUILDING_MYLIB #define MYLIB_API __declspec(dllexport) #else #define MYLIB_API __declspec(dllimport) #endif #else #define MYLIB_API #endif void MYLIB_API myApiFunction();
Another reason might be a code processing tool. Perhaps you have a tool that parses the source code by extracting a list of functions with a specific marker. You can define such a marker as an empty macro.
source share