Empty structure in C

后端 未结 7 1049
臣服心动
臣服心动 2020-12-01 14:49

I have a structure with no members (for the moment) and I would like to know if it is possible to suppress the warning I get:

warning: struct has no members         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 14:54

    C99 standard is somewhat ambiguous on this, but seems to say that an empty struct should have non-zero size.

    6.2.6.1 Except for bit-fields, objects are composed of contiguous sequences of one or more bytes, the number, order, and encoding of which are either explicitly specified or implementation-defined.

提交回复
热议问题