Question

im casting

char* something= reinterpret_cast<char*>(&GPBuffer);

and than back to:

char temp1 [400];

string buffer = reinterpret_cast<string&>(temp1);

I know it looks stupid to cast string to char* but this is what i need and it works!!

but if i pass the "something" (throw internal que) to a different thread, and i try to cast back, i receive:

0x00000000009bb2dd in std::basic_string, std::allocator >::operator= (this=0x48410790, __str=Traceback (most recent call last): File "/usr/share/gdb/python/libstdcxx/v6/printers.py", line 469, in to_string return self.val['_M_dataplus']['_M_p'].string (encoding, length = len) OverflowError: signed integer is less than minimum ) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:486

anyone is familiar with this error?

Was it helpful?

Solution

You take a plain char array, cast it to string, and just expect it to work? You're braver than I thought.

Anyway, the error you're getting comes from the debugger's Python script that tries to print a std::string in a readable form. Since what you have is anything but a valid std::string, some check in the script triggers and throws the error. It's not a normal C++ error.

OTHER TIPS

I would use a void*

void* something = (void*)(&PGBuffer);

string my_fancy_string((char*)something)

Besides that, I wouldn't use a std::string for keeping buffers of raw data and just use a char array for that, but that's your choice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top