This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ interop issue due to non-null pointers


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]