0

I included <windows.h> header into my project, and I received following error:

Error C2467: illegal declaration of anonymous 'struct' (wingdi.h)

wingdi.h header (it contains anonymous struct within _devicemodeW) is included by windows.h. Such situation conflicts with my current language settings (disable language extensions /Za) As I understand, WinApi always uses language extensions and if I want to use winapi I should always use language extensions? (I am using msvc2015)

Alex Aparin
  • 4,393
  • 5
  • 25
  • 51
  • 4
    Sadly that's the case. Microsoft adds language extension because it facilitates their own code. But if you think about, they aren't alone. The LINUX kernel is written with a fair bit of GCC extensions in use. I suggest implementing an abstraction layer for what you need. That way you can build just a couple of files with extensions enabled – StoryTeller - Unslander Monica May 15 '17 at 13:33
  • @StoryTeller The Linux kernel's header files aren't an SDK for application development. I've never had too enable some GCC extension to be able to use GNU C LIbrary (glibc) headers. Many useful GCC extensions are **conforming**; they can be left enabled even in compilation modes that implement all required ISO C diagnostics, and recognize all ISO C constructs. – Kaz May 15 '17 at 14:02
  • 1
    You can specify /Za on each individual source code file in the project. So simply move code that requires the #include into a file that you then can compile without it. Which then automatically becomes the one that you will have to tinker with when you have to port. Easy peasy. – Hans Passant May 15 '17 at 14:04
  • @Kaz - Yes, the public windows headers are bad. The point about compiler extensions to facilitate specific projects, still stands however. And many GCC extensions *are not* conforming as well. So I have no idea what point you are arguing. – StoryTeller - Unslander Monica May 15 '17 at 14:05
  • @Kaz infinite support for header files that don't make compiling gruesome – Passer By May 15 '17 at 14:11
  • 2
    See [Are "anonymous structs" standard? And, really, what \*are\* they?](http://stackoverflow.com/questions/14248044/are-anonymous-structs-standard-and-really-what-are-they) for discussion, as well as the workaround: `#define NONAMELESSUNION`. This disables anonymous structures and unions. – Raymond Chen May 15 '17 at 14:20
  • @RaymondChen System headers responding to identifiers in an ordinary namespace ... grrr! – Kaz May 17 '17 at 13:15
  • @Kaz News flash: System headers also inject tons of identifiers into an ordinary namespace. – Raymond Chen May 17 '17 at 13:44

0 Answers0