Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

HALP

Name: Anonymous 2007-02-10 18:58

char temp4[3];
unsigned long int FileStart;
FileStart = (temp4[3] << 24) | (temp4[2] << 16) | (temp4[1] << 8) | (temp4[0]);

This was supposed to take four bytes and turn them into a long int. How do I do this so that the << doesn't turn every byte other than the first one into 'FF'?

Name: Anonymous 2007-02-11 6:24

The first creates the the string of bytes on the stack, including terminating null.

I checked with GCC and it doesn't generate any obvious memory copies. printf'ing an array declared as being too short does stop it from including the terminating NULL (which that post above didn't imply) and therefore messes up the output, but I only have access to a Linux shell and gcc 3, so no -fdump-tree-* and no stack format I understand to tell me how this works.

Regardless, it's a bad habit to think that the compiler generates copies if your code doesn't try to write to anything. You should know how optimization works.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List