Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <a3nsb9-3pf.ln1@wilbur.25thandClement.com> (permalink) |
|---|---|
| From | William Ahern <william@wilbur.25thandClement.com> |
| Subject | Re: struct with one member: padding? |
| Newsgroups | comp.lang.c, comp.unix.programmer |
| References | <jsfckr$drq$1@speranza.aioe.org> |
| Date | 2012-06-27 18:03 -0700 |
Cross-posted to 2 groups.
In comp.unix.programmer Mark <mark_cruzNOTFORSPAM@hotmail.com> wrote:
> Hello
> on many (all?) unix implementations IP address structure is designed this
> way:
In 2012 there are IPv4 addresses and IPv6 addresses, and all extant systems
support both. Therefore, your statement is incorrect because struct in_addr
is no longer sufficient to store an IP address. Indeed, there is no standard
data structure to hold an IP address anymore, for better or worse. The
closest standard data structure is a struct sockaddr_storage.
If you need to manipulate IP addresses in non-trivial ways, it's probably
best to just define your own data structures.
> struct in_addr
> {
> unsigned long s_addr;
> };
> Does the Standard allow a C comiler to add padding in such structure? If
> it so, then we have to always 'memset' in_addr to 0 before use.
There's no requirement that you must use memset. Assigning 0 to .s_addr
should suffice. In fact, I don't believe it's common to use memset that
way at all. You may be thinking of using memset to 0 initialize struct
sockaddr and cousins.
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
struct with one member: padding? "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2012-06-27 12:33 -0400
Re: struct with one member: padding? John Gordon <gordon@panix.com> - 2012-06-27 16:40 +0000
Re: struct with one member: padding? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-27 18:27 +0100
Re: struct with one member: padding? Ben Pfaff <blp@cs.stanford.edu> - 2012-06-27 09:57 -0700
Re: struct with one member: padding? China Blue Meanies <chine.bleu@yahoo.com> - 2012-06-27 12:15 -0700
Re: struct with one member: padding? Andrew Cooper <amc96@cam.ac.uk> - 2012-06-27 22:52 +0100
Re: struct with one member: padding? scott@slp53.sl.home (Scott Lurndal) - 2012-06-27 23:42 +0000
Re: struct with one member: padding? William Ahern <william@wilbur.25thandClement.com> - 2012-06-27 18:03 -0700
csiph-web