I was recently looking over some code and I've stumble upon this:
class IDATA_EXPORT IData {
/* .... */
}
Where IDATA_EXPORT
is not more than :
#ifndef IDATA_EXPORT
#define IDATA_EXPORT
#endif
What is IDATA_EXPORT
in this case? (I mean, is it type like int, char etc ... ?)
__FILE__ This macro expands to the name of the current input file, in the form of a C string constant. This is the path by which the preprocessor opened the file, not the short name specified in ' #include ' or as the input file name argument. For example, "/usr/local/include/myheader.
(C++11) The predefined identifier __func__ is implicitly defined as a string that contains the unqualified and unadorned name of the enclosing function. __func__ is mandated by the C++ standard and is not a Microsoft extension.
Macros and its types in C/C++ A macro is a piece of code in a program that is replaced by the value of the macro. Macro is defined by #define directive. Whenever a macro name is encountered by the compiler, it replaces the name with the definition of the macro.
Most likely at some point in time, or under some conditions it was defined as (for example, under MSVC):
#define IDATA_EXPORT __declspec(dllexport)
Which was used to indicate the classes to publicly export from the library.
Using the macro, the developer could alternate between exporting classes and not exporting anything, without having to go over each individual class.
This is often part of a macro pattern which alternates between importing and exporting classes, depending on whether the code is compiled from the library, or from a program dependent on the library. It would then look something like:
#ifdef IS_LIBRARY // <--this would only be defined when compiling the library!
#define IDATA_EXPORT __declspec(dllexport)
#else
#define IDATA_EXPORT __declspec(dllimport)
#endif
For more information, see dllexport, dllimport on MSDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With