1999.02.25 13:57 "Re: Pb with LZW", by Peter Nielsen

1999.02.25 13:57 "Re: Pb with LZW", by Peter Nielsen

>From: Bruno Ledoux [mailto:bruno_ledoux@binuscan.com]
>>When I compile the tif_lzw.c file with default speed optimisation in
>>Visual C++5, I get strange colors when decompressing
>>TIFF LZW files. If I compile the tif_lzw.c file with all optimisation
>>off, things are working correctly!
>
>it's not your code. the same thing happens to me. VC5, and v34b37.

Hello Chris, Bruno, all,

The reason for this problem is most probably the sad fact that Microsoft VC++ does optimizations with the shift operator that violates the C/C++ standard. Here's a simple example (32-bit int assumed):

unsigned int int32bit = 1;
unsigned int shift = 33;
unsinged int result = int32bit << shift;

According to the C/C++ standard the result should be zero (0) if all bits are shifted out.

Microsoft, on the other hand has redefined the standard and the manual says that the result is "undefined" if all bits are shifted out.

Solution: Use a better compiler that adheres to standards.

Best regards,
        Peter Nielsen