Originally Posted by
Prediluted
Ok, so I shouldn't even bother to try and print the values in the char* because they will be all messed up right?
I have no idea what you mean by this. (EDIT: OH, if you mean you're trying to use cout to print the characters themselves (as opposed to the numeric value of the characters), then yes that's probably garbage.) Let's suppose, for fun, that we have an array of six shorts, 0x1234, 0x2345, 0x3456, 0x789a, 0x89ab, and 0x9abc. From your perspective, it looks like this:
Code:
+----+----+----+----+----+----+
|1234|2345|3456|789a|89ab|9abc|
+----+----+----+----+----+----+
^
|
+--- base address of array
so that pack[0] is 0x1234, etc. When you pass that base address to your data thing, it gets reinterpreted as a bunch of characters, so now you have twelve bytes of this:
Code:
+--+--+--+--+--+--+--+--+--+--+--+--+
|34|12|45|23|56|34|9a|78|ab|89|bc|9a|
+--+--+--+--+--+--+--+--+--+--+--+--+
^
|
+---- base address
The byte-swapping is the endianness I mentioned before -- most modern computers are little-endian, meaning the least significant bytes are stored first. But in any event, that's what you should see on the other end of the pipe. Now what the other end of the pipe is going to do with the data I have no idea, but that's what it should see.
As to receiving, you first need to allocate memory for the buffer, then do something like
Code:
short int *interpreted_data = (short int *)char_pointer_of_received_data;
assuming the data you get is supposed to be interpreted as short ints.