1

I'm porting some (working) code from Linux to Windows 8. I'm using DDK.

typedef struct {
    unsigned int test1;
    unsigned int test2;
} settings;

const settings vp_settings = {
    .test1 = 1,
    .test2 = 1
};

What is different about the Windows DDK compiler and GCC that makes this invalid? The error I'm getting, assuming typedef struct { is line 1 and numbering continues normally:

(7) : error: C2059: syntax error : '.'

How can I write this in such a way that there will be no syntax errors? I would like to keep the same member names so I don't need to alter the rest of the code base. Is the period superfluous and can be removed?

wanovak
  • 6,117
  • 25
  • 32

2 Answers2

2

Q: What's wrong with (vanilla):

const settings vp_settings = {
    1, /* test1 */
    1  /* test2 */
};

PS:

How to rewrite C-struct designated initializers to C89 (resp MSVC C compiler)

This looks like a C99 thing ... and AFAIK MSVS does not fully support C99...

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • @sarnold - I understand. My point was that Microsoft has never been accused of being very agressive about supporting the latest/greatest open standards, and the best approach is probably, as the link above suggests, "Just drop the field name tags". IMHO... – paulsm4 Jun 28 '12 at 22:59
  • 1
    Silly me to expect them to implement a neat feature only 13 years after it's been specified. :) – sarnold Jun 28 '12 at 23:01
  • Microsoft has explicitly stated that they're not interested in supporting C past C90 (except for those features that are included in newer C++ standards). See [this interview with Herb Sutter](http://www.drdobbs.com/cpp/interview-with-herb-sutter/231900562). – Keith Thompson Jun 29 '12 at 00:08
1

Looks like your compiler does not support C99 designated initializers.

Perhaps your compiler requires a command line switch to enable C99 features?

sarnold
  • 102,305
  • 22
  • 181
  • 238