I’m working with quite a big codebase which compiles fine in linux but vc++ 2008 spits errors.
The problem code goes like this:
Declaration:
typedef float vec_t;
typedef vec_t vec2_t[2];
The codebase is littered with in-place construction like this one:
(vec2_t){0, divs}
Or more complex:
(vec2_t){ 1/(float)Vid_GetScreenW(), 1/(float)Vid_GetScreenH()}
As far as I know, this code constructs a struct, then converts it to an array and passes the address to the function. I personally never used in-place construction like this so I have no clue how to make this one work.
The compiler produces a bunch of syntax errors like these:
Error 2 error C2143: syntax error : missing ')' before '{'
Error 3 error C2059: syntax error : ')'
Error 4 error C2143: syntax error : missing ';' before '{'
I don’t maintain the linux build, only the windows one. And I can’t get it to compile. Is there some switch, some macro to make vc++ compile it?
Maybe there is a similar nifty way to construct those arrays and pass them to the functions in-place that compiles just fine in vc++?
You’re using a GCC extension that MSVC simply doesn’t support, “compound literals”, also called “constructor expressions” in older GCC docs.
If you want portable code, I think you’ll need to change the code to declare the structs normally and initialize them with initializers that have constants expressions or using standard assignments (or use something like MinGW as your Windows compiler, if that’ll do the trick).