c/10339: strncmp generates imPure code

Wolfgang Bangerth bangerth@ices.utexas.edu
Mon Apr 7 18:11:00 GMT 2003



> It generates a memcmp of 4 bytes when one of the arguments
> is 3 bytes long.

You're a little terse in your descriptions of the problem :-]

I think I understand now what you mean: with -O, gcc optimizes the strncmp 
away and replaces it by a call to memcmp. However, it doesn't take into 
account that strncmp compares _at most_ n  characters, but that the actual 
number may be less than n if one of the two strings is shorter. memcmp on 
the other hand always does n bytes.

Is that what you meant?

Thanks
  Wolfgang

-------------------------------------------------------------------------
Wolfgang Bangerth              email:            bangerth@ices.utexas.edu
                               www: http://www.ices.utexas.edu/~bangerth/




More information about the Gcc-bugs mailing list