[英]C++11 auto variable : float array vs auto
Size of float array declared is suing auto is different than actual size. 声明的浮点数组的大小是suing auto与实际大小不同。 why is it so ??
为什么会这样?
For eg: 例如:
declaration: 宣言:
float duto[] = {2.2222f,2.223f,34.5f,1.0f,9.0f};
auto dutot = {2.2222f,2.223f,34.5f,1.0f,9.0f};
Size print: 尺寸打印:
std::cout << " float array size v: " << sizeof(duto)<<std::endl;
std::cout << " auto v: " << sizeof(dutot)<<std::endl;
Output: 输出:
float array size v: 20
auto v: 16
auto dutot = {2.2222f,2.223f,34.5f,1.0f,9.0f};
auto
here is actually deduced as initializer_list<float>
. auto
here实际上被推断为initializer_list<float>
。 so you are printing the size of initializer_list<float>
. 所以你要打印
initializer_list<float>
的大小。
I just took a look at initializer_list
implementation in g++ 4.8.2 on my ubuntu 14.04. 我刚刚在我的ubuntu 14.04上看了g ++ 4.8.2中的
initializer_list
实现。 it contains two members _M_array
and _M_len
. 它包含两个成员
_M_array
和_M_len
。 _M_array
is a pointer, _M_len
's type is size_t. _M_array
是一个指针, _M_len
的类型是size_t。 So I guess your machine is 64bit. 所以我猜你的机器是64位。 since pointer and size_t are usually 8 bytes on 64bit platform.
因为指针和size_t通常是64位平台上的8个字节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.