Is sizeof(void()) a legal expression?

前端 未结 6 1653
暖寄归人
暖寄归人 2020-12-09 07:03

From [5.3.3/1], I found that:

The sizeof operator shall not be applied to an expression that has function or incomplete type

Fro

6条回答
  •  鱼传尺愫
    2020-12-09 08:09

    As already highlighted in the docs here http://en.cppreference.com/w/cpp/language/sizeof

    Notes

    sizeof() cannot be used with function types, incomplete types, or bit-field glvalues.

    Since void() is a function type, so its not a valid type of sizeof()

    Note:

    void() is a function that takes no arguments and returns nothing

    Quoting a Example from Docs:

    //<< "size of function: " << sizeof(void()) << '\n'  // error
    

    So Answers to your questions:

    1)No it is not a legal Expression.

    2)It will show as 1 , but will show a warning

    3)same as 1).

提交回复
热议问题