What is the return type of sizeof operator?

前端 未结 3 1773
遥遥无期
遥遥无期 2020-12-18 17:31

What is the return type of sizeof operator? cppreference.com & msdn says sizeof returns size_t. Does it really return a size_t? I\'m using VS2010 Professional, and targ

3条回答
  •  时光取名叫无心
    2020-12-18 18:23

    size_t is an alias of some implementation-defined unsigned integral type. In C++ opposite to C where sizeof operator may be applied to VLA arrays the operand of sizeof operator is not evaluated (at run time). It is a constant. If the value of sizeof operator can be fit into int type the compiler does not issue a warning. In the second example std::strlen is evaluated at run time so its result can do not fit into int so the compiler issues a warning. You could substitute std:;strlen with your own constexpr function (some recursive function). In this case if the result can fit into int I think that the compiler will not issue a warning.

提交回复
热议问题