Ok, time for another “what’s wrong with this code” problem.
This time, I’m writing a DLL. Nothing complicated, just a plain old DLL. As is expected, I publish a header file for my api:
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the NIFTY_API_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// NIFTY_API_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#define NIFTY_API_API __declspec(dllexport)
#define NIFTY_API_API __declspec(dllimport)
NIFTY_API_API int MyNiftyAPI(void);
You’ll notice that this header is almost identical to the header file that Visual Studio produces when you ask it to make a DLL. Even so, there’s a bug in this header file.
Your challenge is to figure out what the bug is. It’s subtle, this time, but important (although Raymond and I have touched on it before). Btw, the fact that it uses the non standard __declspec is NOT the bug. That’s syntactic sugar that could be easily removed without removing the error.
As usual, answers and kudos tomorrow.