POD & arithmétique de pointeur
Hello,
Soit le morceau de code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
struct float3
{
float x;
float y;
float z;
}
float3 variable;
variable.x = 1.5f;
variable.y = 5.2f;
variable.z = 8.3f;
std::cout << &(variable) << std::endl;
std::cout << sizeof(float) << std::endl;
std::cout << &(variable + sizeof(float)) << std::endl;
std::cout << &(variable.x) << std::endl;
std::cout << &(variable.y) << std::endl;
std::cout << &(variable.z) << std::endl; |
La sortie est la suivante :
Code:
1 2 3 4 5 6
| 0012FE1C
4
0012FF60
0012FE1C
0012FE20
0012FE24 |
Je ne m'explique pas la valeur de la 3ème ligne. Selon moi, elle aurait dû être identique à la 5ème.
En revanche, si je fais :
Code:
1 2
| float* dodo = reinterpret_cast<float*>(&(variable));
dodo++; |
J'obtiens la bonne valeur.
Si quelqu'un a une explication... Merci.