Eric Blake wrote in <20221130150909.pei323lktieb4...@redhat.com>: |On Wed, Nov 30, 2022 at 08:54:03AM -0600, Eric Blake via austin-group-l \ |at The Open Group wrote: |>> ... |>>|https://austingroupbugs.net/view.php?id=561 |> |> First, I chose that wording because 'sizeof(struct |> sockaddr_un.sun_path)' doesn't compile. You are right that 'sizeof |> NAME.sun_path' does compile, if NAME is an expression of type struct |> sockaddr_un, but the sentence becomes longer to introduce some object |> named NAME of the correct type just to get to the shorter sizeof |> expression. However, we can make that edit if it makes sense. | |Having written that, I did test that 'sizeof(((struct |sockaddr_un*)0)->sun_path)' compiles with gcc, although I'm less |certain of whether the C standard permits that (or even if that
I would assume a lot of software will break if not; i use #define su_FIELD_SIZEOF(T,F) sizeof(su_S(T *,su_NIL)->F) (in varying forms) ever since i program in C and C++. |permission has changed over time) - the expression argument to sizeof |is unevaluated, which counters the argument that you can't normally |evaluate a dereference of a NULL pointer. Now ... i grep(1)ped the Linux kernel 5.15, and i see a lot of matches for "grep -Fr '0)-", among of which is, in Documentation/process/coding-style.rst Similarly, if you need to calculate the size of some structure member, use .. code-block:: c #define sizeof_field(t, f) (sizeof(((t*)0)->f)) I hope the C standard would have to be changed if this becomes invalid. (Unless they start to invent useful things that provide those things that everybody needs and uses for decades, and which are still missing.) --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)