https://www.austingroupbugs.net/view.php?id=561#c6085 (the accepted
text) suggests that…

     versions,  the  size  is  typically in the range 92 to 108. An application 
can
     deduce the size by using <tt>sizeof(((struct sockaddr_un 
*)0)->sun_path)</tt>.

… but I was recently told that attempting that is UB because it
dereferences a nil pointer, even though it’s only within a sizeof,
and the current C editor didn’t deny that, just stating that
“This has been hotly debated for years” and to use offsetof instead
(which does not work for the last member, incidentally) because the
implementation of offsetof may do “crimes” an application cannot.

The actual discussed thing was…
        #define FIELD_SIZEOF(t,f) (sizeof(((t*)0)->f))
… so basically the same.

Note that sizeof-offsetof is not the same because there may be padding.

bye,
//mirabilos
-- 
In traditional syntax ' is ignored, but in c99 everything between two ' is
handled as character constant.  Therefore you cannot use ' in a preproces-
sing file in c99 mode.  -- Ragge
No faith left in ISO C99, undefined behaviour, etc.

  • probable UB in recen... Thorsten Glaser via austin-group-l at The Open Group

Reply via email to