I believe that this kind of thing with i/o streams
std::cout << a(&val) << val;
generates an Unspecified Behavior.
The std::cout function will print the arguments in the order you provided, but it cannot guarantee that they will be executed from lef-to-right or right-to-left.
I think that the compiler is the one that is translating this to a random order of execution. DevC++ (gcc?) did it left-to-right as you expected but the vc++ from Visual Studio did it differently.
Anyhow, I think it is better to break this line into two as you have shown above.