Variables with "__declspec(dllimport)" Should Not Be Initialized Where Used

Initializing dllimport variable in user code in Intel® C++ Compiler 10.1 and later leads to compiler error:--
In older compilers, this was treated as a warning.

Sample code to illustrate the initialization in user code:--

typedef struct structure {
unsigned int length;
void * V;
} S1, *S2;

static const  S1 myarr[] = {
{1, (void *)"0x1234"}

__declspec(dllimport) S2 s = ((S1 *)myarr)+3;

dllimp.cpp(19): error: variable "s" may not be initialized
__declspec(dllimport) S2 s = ((S1 *)arr)+0;

The proper code should be :--

__declspec(dllimport) S2 s

While the value should be set in the DLL , the code should simply import and use the value.

This is not a compiler error, but a user error.

Command line for compilation:--

icl /c dllimp.cpp
For more complete information about compiler optimizations, see our Optimization Notice.