Can sizeof return 0 (zero)

后端 未结 10 1560
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 08:14

Is it possible for the sizeof operator to ever return 0 (zero) in C or C++? If it is possible, is it correct from a standards point of view?

10条回答
  •  盖世英雄少女心
    2020-11-28 08:57

    If you have this :

    struct Foo {}; 
    struct Bar { Foo v[]; }
    

    g++ -ansi returns sizeof(Bar) == 0. As does the clang & intel compiler.

    However, this does not compile with gcc. I deduce it's a C++ extension.

提交回复
热议问题