I am going through a implementation of a LZSS decompression algorithm where there is a buffer of 4096 chars (or whatever size you like). This implementation outputted the file to a char* where as I wanted to output a file using std::ofstream. I did get this to work but in a weird/quirky fashion (at least to me). It has something to do with the assign operator from what I can tell. All the types are the same (char)
If have
outputFileStream.write((char *) &buffer[byteIndex1++ & 0xFFF]);
buffer[byteIndex2++ & 0xFFF] = buffer[byteIndex1 & 0xFFF];
this will fail and give me corrupt data but if I have this
char temporary;
buffer[byteIndex2++ & 0xFFF] = temporary = buffer[byteIndex1++ & 0xFFF];
outputFileStream.write((char *) &temporary, 1);
that will work. Am I not understanding the order of operations that are taking place? (Execution of operations right to left) If I am then would not those two code snippets work the same?