Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is sizeof in C++ evaluated at compilation time or run time?

For example result of this code snippet depends on which machine: the compiler machine or the machine executable file works?

sizeof(short int) 
like image 780
ogzylz Avatar asked Apr 10 '10 22:04

ogzylz


People also ask

Is sizeof a compile time operator?

Sizeof is a much used operator in the C or C++. It is a compile time unary operator which can be used to compute the size of its operand. The result of sizeof is of unsigned integral type which is usually denoted by size_t.

Why is sizeof compile time?

C++ doesn't actually store the metadata for objects at runtime so size checking must be compile time. For an example of how C++ doesn't validate size, declare an array of int of some arbitrary size and read past the end of it.

Is size Of Stack determined at compile time?

It is not possible because some inputs are not known until runtime.

What is determined at compile time?

In computer science, compile time (or compile-time) describes the time window during which a computer program is compiled. The term is used as an adjective to describe concepts related to the context of program compilation, as opposed to concepts related to the context of program execution (runtime).


1 Answers

sizeof is a compile time operator.

like image 159
Billy ONeal Avatar answered Sep 22 '22 19:09

Billy ONeal