Why can't we declare a variable of type void?

后端 未结 7 1644
盖世英雄少女心
盖世英雄少女心 2020-12-08 09:43

I\'m looking for a formal explanation of that fact in the Standard. I\'ve found what 3.9.1/9 says and trying to give an explanation used that section.

S

7条回答
  •  不思量自难忘°
    2020-12-08 10:14

    void is an incomplete type - you can only declare pointers to them and use them in function signatures. Obviously, extern Foo f; is permitted because struct Foo can be defined in another compilation unit (and if it's not the error will be detected by the linker), but void can't ever be "defined" (and the compiler knows this, of course) so void's quite special in this case.

提交回复
热议问题