Why sizeof is an operator, not a function?
To calculate the size of an object, we need the type information. This type information is available only at compile time. At the end of the compilation phase, the resulting object code doesn’t have (or not required to have) the type information. Of course, type information can be stored to access it at run-time, but this results in bigger object code and less performance. And most of the time, we don’t need it. All the runtime environments that support run time type identification (RTTI) will retain type information even after compilation phase. And if, something can be done in compilation time itself, why do it at run time? More importantly, HOW can it be a function when the operand is a type, not an expression. Even expressions subject to integral promotion are problematic.
Popularity: 10%