How to correctly fix “zero-sized array in struct/union” warning (C4200) without breaking the code?

后端 未结 6 1379
北海茫月
北海茫月 2021-02-05 07:52

I\'m integrating some code into my library. It is a complex data structure well optimized for speed, so i\'m trying not to modify it too much. The integration process goes well

6条回答
  •  我在风中等你
    2021-02-05 08:24

    If this is a MSVC compiler (which is what the warning message tells me), then you can disable this warning using #pragma warning, ie.:

    #pragma warning( push )
    #pragma warning( disable : 4200 )
    struct _TREEDATSTR
    {
        BYTE btLen;
        DWORD dwModOff;
        BYTE btPat[0];
    };
    #pragma warning( pop )
    

    BTW, the message about the copy-constructor is not creepy, but a good thing because it means, that you can't copy instances of _TREEDATSTR without the unknown bytes in btPat: The compiler has no idea how big _TREEDATSTR really is (because of the 0-size array) and therefore refuses to generate a copy constructor. This means, that you can't do this:

    _TREEDATSTR x=y;
    

    which shouldn't work anyway.

提交回复
热议问题