This has gone far beyond the original question, that said thanks for all the responses. There seems to be alot of disagreement on what reinterpret_cast can safely do. Now I know shouldn't use it, and I don't in normal code, more I was just curious on what it can do. It seems a bit silly that any use of reinterpret_cast would be undefined/implementation specific, but perhaps I'm wrong here?
I was under the impression casting through reinterpret_cast and back, as long as the alignment and size of the intermediate was appropriate, that you can safely (and in a defined/non-implementation specific way) get the original value back (whatever that may be), and use it. For example:
int a = 5;void* b = &aint c = *reinterpret_cast<int*>(b);
is undefined?
Also this one thing piqued my interest:
Quote:Original post by ApochPiQ
volatile is almost always the wrong thing to use, especially when threading is concerned.
If volatile is not to be used for inter-thread communication what do you use?
Whether it be message passing, mutex's, critical sections, barriers, or what-have-you, they all rely on volatile under the hood don't they? Apart from going straight down to assembly or calling as OS supplied routine (both of which are undefined/implementation specific) you don't have a lot of other options.
[Edited by - Ryan_001 on August 28, 2010 7:14:06 PM]