数据类型的大小,而不使用的sizeof [英] size of a datatype without using sizeof
问题描述
我有一个数据类型,比如 X
,我想知道它没有宣布该类型,当然还有一个变量或指针大小,而无需使用的sizeof
运营商。
I have a data type, say X
, and I want to know its size without declaring a variable or pointer of that type and of course without using sizeof
operator.
这可能吗?我想用它含有的大小和数据类型的范围标准头文件,但不以用户定义的数据类型。
Is this possible? I thought of using standard header files which contain size and range of data types but that doesn't work with user defined data type.
推荐答案
在我看来,这种适合的我怎么添加两个整数,而无需使用++ + = +还是?一类。这是在浪费时间。您可以尝试通过做这样的事情避免不确定的行为的怪物。
To my mind, this fits into the category of "how do I add two ints without using ++, += or + ?". It's a waste of time. You can try and avoid the monsters of undefined behaviour by doing something like this.
size_t size = (size_t)(1 + ((X*)0));
请注意,我没有的声明的类型或指针到 X中变量
。
Note that I don't declare a variable of type or pointer to X
.
这篇关于数据类型的大小,而不使用的sizeof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!