extern const for memory allocation?
I was reading Microsoft's Inside COM, and I couldn't quite understand one of the comments for a code snippet.
There are two files of interest.
File 1 : Iface.h
Code:
extern "C"
{
extern const IID IID_IX
}
File 2 : GUID.cpp
Code:
#include <objbase.h>
extern "C"
{
extern const IID IID_IX = {0x32bb8320, 0x41b, 0x11cf, ...};
// The extern is required to allocate memory for C++ constants
}
There are two more files associated with this example, one is a file that implements a COM component, and the other is a file that implements a COM client. They both #include "Iface.h", and GUID.cpp are linked to both the component and client when compiled.
Here, Iface.h is created to "declare" IID_IX variable, and GUIDS.cpp is created to "define" the variable. So I understand why extern key word is used for the variable in Iface.h, but I don't undersatnd why it is used in GUIDS.cpp. So I turned to the comment below the definition of the variable in the GUIDS.cpp file, but I still couldn't make much sense out of it. Particularly, I didn't know what it meant when it stated that extern is requried to allocate memory for C++ constants. I would appreciate for some clarifications. Thank you.