C++ interop issue due to non-null pointers
Florian Weimer
fweimer@redhat.com
Wed Jun 18 07:28:00 GMT 2014
On 06/18/2014 09:24 AM, Jakub Jelinek wrote:
>> You're returning a T *, not a void *, and C++ requires that pointers are
>> properly aligned even if they aren't dereferenced.
>
> C qsort doesn't return anything and the comparison function returns int.
>
> extern void qsort (void *__base, size_t __nmemb, size_t __size,
> __compar_fn_t __compar) __nonnull ((1, 4));
>
> It is the C qsort that has undefined behavior if the 1st or 4th argument is
> NULL. So I don't see what is wrong on:
> qsort (ptr ? (void *) ptr : "", nmemb, sizeof (*ptr), compar);
Ah, we have a misunderstanding. I assumed you were talking about the
data() member of std::vector.
--
Florian Weimer / Red Hat Product Security Team
More information about the Gcc
mailing list