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 Wed, Jun 18, 2014 at 09:18:10AM +0200, Florian Weimer wrote:
> On 06/17/2014 05:00 PM, Jakub Jelinek wrote:
> 
> >>>GCC will likely not optimize it away at this point, but having code with
> >>>undefined behavior is just asking for future trouble.  Just use "" instead?
> >>
> >>It's always const and may lack sufficient alignment.  The former isn't a
> >>problem in C++ (I think), but the alignment is an issue.
> >
> >Alignment for what?  You don't specify any alignment to the C qsort,
> 
> 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);

	Jakub


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