I'm using the code below to find alignment properties of some attributes. I know that storing the NULL
pointer is defined behaviour and pointer operations also are defined behaviour and only unreferencing the NULL (and other invalid values) pointer invokes undefined behaviour. My questions is simple: Does the ->
implies unreferencing the pointer (thus causing undefined behaviour in the code below)?
#include <iostream>
void f(void *p)
{
std::cout << p << std::endl;
}
struct X
{
int a;
int b;
};
struct Y
{
int a[2];
int b;
};
int main()
{
X *x = NULL;
Y *y = NULL;
f(&x->b);
f(&y->b);
}