Steve Summit via tz said:
There are some decent resident language lawyers over on Stack Overflow these days. I asked this question there, and several posters have cited language from C17 which seems (like the Posix language others have mentioned here) to directly contraindicate gcc's behavior:
These utilities [qsort, bsearch] make use of a comparison function to search or sort arrays of unspecified type. Where an argument declared as size_t nmemb specifies the length of the array for a function, nmemb can have the value zero on a call to that function; the comparison function is not called, a search finds no matching element, and sorting performs no rearrangement. Pointer arguments on such a call shall still have valid values, as described in 7.1.4.
[C17 Sec. 7.22.5]
That text was added in C99; it wasn't in C90. I think it might have been my idea; it certainly feels familiar. -- Clive D.W. Feather | If you lie to the compiler, Email: clive@davros.org | it will get its revenge. Web: http://www.davros.org | - Henry Spencer Mobile: +44 7973 377646