   Code that works on Linux and Windows but not on Macintosh
  Hi,I made some code that works on Windows and Linux. However, someone emailed me to let me know that it doesn't work for him, and he works on Macintosh, on mac OSX 10.4 and an Intel processor (not a motorola one, if that could make a difference).I don't have a Mac available myself so I can't debug this.He gets an error code -21, which means the following part of the code doesn't work.    //go to first boundary of byte    while(bp % 8 != 0) bp++;    //read LEN (2 bytes) and NLEN (2 bytes)    unsigned long LEN = 256 * in[bp / 8] + in[bp / 8 + 8]; bp += 16;    unsigned long NLEN = 256 * in[bp / 8] + in[bp / 8 + 8]; bp += 16; //check if NLEN is really the one's complement of LEN ("&" with 1111111111111111 because it's 16 bit ones complement)    if( (LEN & 65535) != ((~NLEN) & 65535) ) return -21; //error: NLEN is not one's complement of LEN*) in is an unsigned char* buffer*) bp is a bit pointer (since it's a bit pointer, is it possible that ENDIAN-ness inconsistencies could be the cause?). Single bits are read like this: (in[bp / 8] >> (bp % 8)) & 1; bp++;This error is at the first part of the code where the bitpointer is used so I'm sure it has something to do with the bitpointer.If needed I can post some more code.EDIT: it could also be in this part of the code, that also uses the bitpointer, and it's possible that the previous part of code I posted isn't the cause, but this part, which makes the above code to run while it shouldn't because of a wrong BTYPE value:    BFINAL = (in[bp / 8] >> (bp % 8)) & 1; bp++;    unsigned long BTYPE = 2 * ((in[bp / 8] >> (bp % 8)) & 1) + ((in[(bp + 1) / 8] >> ((bp + 1) % 8)) & 1); bp += 2;Is there anything in the code I posted, that can cause undefined behaviour on different platforms? Something that would work on Linux and Windows but not on Macintosh?Is the ">>" operator well defined and reliable?Also, the in buffer is read from a file. Are files on Mac read in a different way maybe?Also, if you have a Macintosh, could you please test if the code works for you? It's here: http://student.kuleuven.be/~m0216922/pngloader/, all that's needed to test it is putting those two files in a folder, then make a new main.cpp file and copypaste the example code in the header file into that .cpp file, compile it with gcc for example (or another Mac compiler), put a png file in the folder of the binary, run it, and see if it gives an error, or if it doesn't give an error, prints the dimensions of the png file.I have no Mac so it's impossible for me to figure this out.Thanks a lot for the help!   
  shouldn'tin[bp / 8 + 8];bein[ (bp + 8) / 8];;  shouldn'tin[bp / 8 + 8];bein[ (bp + 8) / 8];;Quote:Original post by Anonymous Postershouldn'tin[bp / 8 + 8];bein[ (bp + 8) / 8];Hey, you're right, or in[bp / 8 + 1].Too bad you're an AP, or I'd rate you up! Thanks :)EDIT: problem fixed and it is working now, it was both the mentioned bug, and the byte order (the other one had to mutliplied by 256) - it wasn't a macintosh problem, it was rather a problem of the macintosh user encountering a file with a situation I hadn't encountered, thereby discovering the bug.[Edited by - Lode on June 21, 2006 8:25:25 AM]