sizeof是否在编译时或运行时求值? [英] Does sizeof evaluate at compile-time or runtime?
本文介绍了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).
这篇关于sizeof是否在编译时或运行时求值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文