Hi, Michal.
  
On Thu, Apr 16, 2026 at 03:16:26PM +0200, Michal SuchАnek wrote:
> On Thu, Apr 16, 2026 at 08:03:30PM +1000, Seth McDonald wrote:
> > | A pointer to void shall have the same representation and alignment
> > | requirements as a pointer to a character type.  Similarly, pointers to
> > | qualified or unqualified versions of compatible types shall have the
> > | same representation and alignment requirements.
> > 
> > So the conversion from const void* to void*, and from void* to char*, is
> > not undefined behaviour.  As such, if char* was used instead of u_char*
> > (which I'm not entirely sure why it isn't already), Evgeniy's workaround
> > would be perfectly conformant to the C standard.
> > 
> > It also doesn't break strict aliasing; unions are explicitly allowed to
> > facilitate interpreting the same memory with incompatible types.
> 
> The problem is discussed at length eg. here:
> https://sqlpey.com/c/c-union-type-punning-behavior-c99-vs-c11-standards-explained/#c-union-type-punning-behavior-c99-vs-c11-standards-explained
> 
> In conclusion there is no explicit allowance, and obtuse compiler
> writers will intepret different union members as unrelated, and point to
> the standard to support such obtuse implementation.

 Despite of absence of explicit allowance, some common sense may be used,
 particularly for situation where union members of primary type have
 the same length and alignment. I can't imagine compiler generating
 different memory addresses for such members.

 It seems me the only problem is alignment of members within union.
 The article cited does not explain why one method is considered "safer"
 then another, and why footnote did not become a part of normative text.
 Maybe there are some additional reasons in addition to alignment, it would
 be nice to know. In any case, thanks for valuable remark.
-- 
 Eugene Berdnikov


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

Reply via email to