Alright, so here is a really weird one. I am reading raw data into a buffer, nothing fancy, my code went like so:
typedef unsigned char Byte;
/* ... */
static Byte SerializeBuffer[2048];
/* ... */
std::streamsize readInBuffer =
data.read((char*)SerializeBuffer, sizeof(SerializeBuffer));
But I would keep getting the compile error message 'error: invalid cast from type ‘void *’ to type ‘std::streamsize’', No idea why the compiler thought that sizeof was a void pointer. Well I tried casting it in several ways, but the same error kept happening. I ended up with this:
std::streamsize dummy = sizeof(SerializeBuffer);
std::streamsize readInBuffer =
data.read((char*)SerializeBuffer, reinterpret_cast<std::streamsize>(dummy));
Which pops up the following: error: invalid cast from type ‘std::streamsize’ to type ‘std::streamsize’
I am at a complete loss. Any other Ideas?
Compiler: gcc 4.4.5
OS: Linux 2.6.35
edit:
Same thing on Visual Studio 2010
If
datais anistream, keep in mind that the memberreadreturns a reference todata(the stream itself), not the number of characters read.The
void *stuff is probably because the compiler, to assign it to thestd::streamsizemember, tries to use the implicit conversion tovoid *(the one that is used when you doif(data) ...), but stillvoid *is not a good match forstd::streamsize.By the way, the information about the number of characters read can be obtained, after the call to
read, using thegcountmethod.