tech-net archive

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

Re: struct sockaddr_storage issues



On Saturday 24 Dec 2022, at 00:49, Mouse wrote:
> getaddrinfo() has its own issues, perhaps most
> notably the definition of the hints argument, which requires either
> writing nonportable C or ignoring future-proofing.  (You have to either
> clear the unused fields by assignment, which ignores future-proofing in
> that it hardwires the set of fields being cleared, or you have to use
> bzero or moral equivalent, which ignores the nonportability of assuming
> all-0-bits is a nil pointer.)

I thought that
  struct addrinfo hint = { 0 };
  hint.ai_flags = ...;
  etc;
would be fully portable and future-proof, according to the "empty
initialization" rule which is supposed to assign pointers to
NULL. And until today I thought this was a valid C89 code, so quite
portable? (I'm not mentioning C99 or C23 initialization features as
that's a different story).

Out of curiosity, how would the above code possibly misbehave, at
least in theory? Any other portability issues you are thinking of?

Best,
Anthony


Home | Main Index | Thread Index | Old Index