[tz] [PROPOSED 1/7] Avoid undefined behavior if no Link lines

Clive D.W. Feather clive at davros.org
Wed Oct 26 16:15:03 UTC 2022


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 at davros.org     | it will get its revenge.
Web: http://www.davros.org  |   - Henry Spencer
Mobile: +44 7973 377646



More information about the tz mailing list