Search code examples
c++functionc++11language-lawyersizeof

Does sizeof(function) makes sense?


I am a bit confused about the sizeof(function). I used to think that sizeof operator operates on class objects, pointers, and references.

What operands can the sizeof operator operate?

Does sizeof(function) make sense?


Solution

  • As per: http://en.cppreference.com/w/cpp/language/sizeof

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

    or from the 2012 Working Draft of the C++ Standard at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf:

    Section 5.3.3 Sizeof "The sizeof operator shall not be applied to an expression that has function or incomplete type, to an enumeration type whose underlying type is not fixed before all its enumerators have been declared, to the parenthesized name of such types, or to an lvalue that designates a bit-field."