Thorsten Glaser wrote in <pine.bsm.4.64l.2307220213100.20...@herc.mirbsd.org>: |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_pat\ | h)</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
The discussion was that Linux kernel makes excessive use of this, and that its documentation even enforces its use (last i looked). So even the palmy-beach-standard-comittee-meeting-on-expenses guys are expected to not mess this up. (Not really sorry for listening ISO C members; the picture i have in mind was W3C, however.) |“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. Offsetof is #if su_CC_VCHECK_CLANG(5, 0) || su_CC_VCHECK_GCC(4, 1) || su_CC_VCHECK_PCC(1, 2) || defined DOXYGEN /*! The offset of field \a{F} in the type \a{T}. */ # define su_FIELD_OFFSETOF(T,F) __builtin_offsetof(T, F) #else # define su_FIELD_OFFSETOF(T,F) su_S(su_uz,su_S(su_up,&(su_R(T *,su_NIL)->F))) #endif --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)