On Thu, Apr 16, 2026 at 11:45:47AM +0300, Evgeniy Berdnikov wrote:
>   Hello.
>   
> On Thu, Apr 16, 2026 at 06:12:24PM +1000, Seth McDonald via isync-devel wrote:
> > The derivation of B from A thus requires casting away the const, which
> > produces a compilation warning in environments using our memrchr()
> > implementation.  For all intents and purposes this warning is
> > unavoidable, so locally supress it for the relevant cast.
> ...
> >  void *
> >  memrchr( const void *s, int c, size_t n )
> >  {
> > +DIAG_PUSH
> > +DIAG_DISABLE("-Wcast-qual")
> >     u_char *b = (u_char *)s, *e = b + n;
> > +DIAG_POP
> >  
> >     while (--e >= b)
> >             if (*e == c)
> 
>  BTW, there is a compiler-independent way to suppress such warning:
> 
>         union { u_char *b; const void *cvoid_b; } ub;
> 
>         ub.cvoid_b = s;
>         u_char *e = ub.b + n;
>         while (--e >= ub.b)
>                 if (*e == c)
>         ...
> 
>  It assumes that pointers to all bare types are represented identically,
>  AFAIK, this is true for all existent C implementations.

Also it breaks the aliasing rules that C fabricates regardless of the
actual use of the data.

As in b and cvoid_b being different types makes them independent
variables regardless of them accidentally occuppying the same memory,
and C is free to flag ub.b as unassigned, optimize out the assignment to
ub.cvoid_b that is never used, etc.

Thanks

Michal


_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to