I came across some code where a pointer was used on the same line of its declaration. This is the essential SSCCE for it:
#include "stdafx.h"
#include <iostream>
struct C
{
uint32_t a;
};
int main() {
C* pC = (C*) malloc(sizeof(*pC)); // <---- ???
pC->a = 42;
std::cout << pC << std::endl;
std::cout << pC->a << std::endl;
free(pC);
}
When I try to do something similar with a uint32
(insert before the free()
):
uint32_t a = a + pC->a;
std::cout << a << std::endl;
Then either nothing is printed for this statement, or while debugging a random value is stored in a
and VS2015 gives me a runtime warning. Errorlevel after execution is 3. I know this can't work.
Why can I use the pointer? Is it even legal? Why isn't the compiler complaining about such statements? Is the statement split into multiple statements behind the scenes?