Compiler: Microsoft Visual C++ 2010 Express, SP1 Project Property: C/C++ Advance Compile As: Compile as C Code (/TC)
Message:
error C2099: initializer is not a constant
Simple Test Case Showing Error:
typedef struct
{
char *stringP;
int lino;
} foo_t;
#define bad {static foo_t foo ={__FILE__,__LINE__};}
#define good {static foo_t foo ={"filename",10};}
int main()
{
bad; // error C2099: initializer is not a constant
good; // no error
return 0;
}
This generates a C2099 error. This code compiles & links correctly under gcc but not Visual C++ 2010 Express (compile as C Code - i.e. /TC option).
intis 32 bits;longis 64 bits -- you are defining some identifiers with misleading names:#define Word16 int;#define Word32 long int. If you can think about using C99 fixed-width types. ` - pmgprobe_). - James McNellisvoid main()! Except in exceedingly rare instances, you should always define main as eitherint main()orint main(int, char**). - Adam Rosenfield