Hello,
I am writing an outgoing data buffer for a program that will be sending it across a socket to a server. When I form this packet, the first 4 bytes are important identifiers to the server. I am assigning the first and second byte ok, but the 3rd and 4th is where I am having a problem.
The 3rd and 4th contain the size of the packet in bytes. Obviously, I am storing this as an unsigned short int. When I go to write to this portion, it has errors when the value is higher than 255.
Here is the basic snippet. I am getting an assertion error on the line where it assigns the unsigned short int. Could anyway take a crack at this?
Edit: I just noticed this. To check to see if my packet structure is correct, I print it to the console. If I choose not to print it to the console, there is no error. Also, I checked the content of the 3rd and 4th bytes and they are correct. Why would this error when I print the characters out? If you want to see the way I output it, just ask, but it's kind of long.Code:char buffer[1024] = {0};
unsigned short int bufferlen = 4;
void sendPacket(unsigned char id)
{
int i, j, k;
int line = 0;
*(unsigned char *)(buffer) = 0xFF;
*(unsigned char *)(buffer + 1) = id;
*(unsigned short int *)(buffer + 2) = bufferlen;
...
}
Edit: Wow, just never mind. I've been recompiling this for 20 mins and this last compile decided to work. I am sorry. Does anyone else get this with visual studio 2008? I changed no code, but just recompiled about 20 times.
Edit: And here we go again, now its erroring. Could this be a compiler issue?

