sizeof是否在编译时或运行时求值?

sizeof是否在编译时或运行时求值?

问题描述:

我对sizeof运算符的评估时间感到困惑.
何时评估sizeof运算符?

I am confused about the evaluation time of sizeof operator.
When does the sizeof operator get evaluated?

它的评估时间(编译时或运行时)是否取决于语言(C?C ++?)?

Does its evaluation time (compile-time or runtime) depend on the language (C? C++?)?

如果在运行时使用C ++创建对象,我们可以使用sizeof吗?

Can we use sizeof in case of objects created at runtime in C++?

在几乎所有情况下,sizeof都是基于静态类型信息(基本上在编译时)进行评估的.

In almost all cases, sizeof is evaluated based on static type information (at compile-time, basically).

C99的可变长度数组(VLA)是一个例外(我认为是唯一的例外).

One exception (the only one, I think) is in the case of C99's variable-length arrays (VLAs).