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

后端 未结 6 1378
北海茫月
北海茫月 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:08

    Try changing it to say btPat[1] instead. I think both C++ and C standards dictate that an array cannot have 0 elements. It could cause problems for any code that rely on the size of the _TREEDATSTR struct itself, but usually these sorts of structs are typecast from buffers where (in this case) the first byte of the buffer determines how many bytes are actually in btPat. This kind of approach relies on the fact that there is no bounds checking on C arrays.

提交回复
热议问题