What is the size of an empty struct in C?

前端 未结 4 1961
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 06:07

According to me, it is zero but there seems to be bit confusion here

I have tested it with gcc compiler and it gives me zero as output. I know that in C++, size of an

4条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 06:14

    In C99: "If the struct-declaration-list contains no named members, the behavior is undefined."

    The syntax doesn't really allow it anyway, though I don't see anything that says a diagnostic is required, which puts it pretty much back in the "undefined behavior" camp.

提交回复
热议问题