C ++ 11 automatic variable: float array vs auto
The size of the declared array float is suing auto differs from the actual one. why is it so?
For example,
:
float duto[] = {2.2222f,2.223f,34.5f,1.0f,9.0f};
auto dutot = {2.2222f,2.223f,34.5f,1.0f,9.0f};
Print size:
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
source to share
auto dutot = {2.2222f,2.223f,34.5f,1.0f,9.0f};
auto
here actually deduced as initializer_list<float>
. so you are printing the size initializer_list<float>
.
I just looked at the implementation initializer_list
in g ++ 4.8.2 on my ubuntu 14.04. it contains two members _M_array
and _M_len
. _M_array
is a pointer, type _M_len
is size_t. So I am assuming your machine is 64 bit. since pointers and size_t are usually 8 bytes on a 64 bit platform.
source to share