[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: need help on #271678 (sizefo struct?)

On Sun, May 15, 2005 at 07:44:25PM -0700, Russ Allbery wrote:

||  This is a woody vs. sarge difference.  On sarge, linux/x25.h says:
||  struct x25_address {
||          char x25_addr[16];
||  };
||  so the current code, with sizeof(struct x25_address) is correct and
||  changing it would actually break the code.  On woody, linux/x25.h says:
||  typedef struct {
||          char            x25_addr[16];
||  } x25_address;
||  which means that sizeof(x25_address) is correct and the current code won't
||  compile (because nothing ever creates a struct x25_address, just an
||  anonymous struct that is typedef'd to x25_address).  This is an
||  incompatible change in the kernel headers, and there isn't any way for the
||  code to compile on both systems without some additional portability work.

If you happen to have a variable (or field or in fact any expression)
of that type (either type "struct x25_address" or type "x25_address"),
then you can take the size of the variable, instead of the size of the
type. So you can do:

    memcpy(&rt.address, &sx25.sx25_addr, sizeof sx25.sx25_addr);

This will work with either definition of sx25_address.

(sizeof is an operator and doesn't need parentheses.  If the argument
is a type, then *that* needs parentheses though.  But I digress.)

Ciao.                                                         Vincent.
Vincent Zweije <zweije@xs4all.nl>    | "If you're flamed in a group you
<http://www.xs4all.nl/~zweije/>      | don't read, does anybody get burnt?"
[Xhost should be taken out and shot] |            -- Paul Tomblin on a.s.r.

Attachment: signature.asc
Description: Digital signature

Reply to: