468,512 Members | 1,088 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

real world example of union in c

what can be the real world example of unions used in c
Oct 13 '06 #1
1 6624
Banfa
9,056 Expert Mod 8TB
The structure used to hold socket addresses (used on at least Windows and Linux)

Expand|Select|Wrap|Line Numbers
  1. struct   in_addr {
  2.     union   {
  3.         struct{
  4.             unsigned  char   s_b1,
  5.                              s_b2,
  6.                              s_b3,
  7.                              s_b4;
  8.         }  S_un_b;
  9.         struct  {
  10.             unsigned  short  s_w1,
  11.                              s_w2;
  12.         }  S_un_w;
  13.         unsigned long  S_addr;
  14.     } S_un;
  15. };
  16.  
  17. struct sockaddr_in{
  18.     short            sin_family;
  19.     unsigned short   sin_port;
  20.     struct   in_addr sin_addr;
  21.     char             sin_zero[8];
  22. };
  23.  
Oct 13 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

49 posts views Thread by Mike MacSween | last post: by
30 posts views Thread by Raymond Hettinger | last post: by
7 posts views Thread by Fred Exley | last post: by
6 posts views Thread by Steven Nagy | last post: by
14 posts views Thread by dost | last post: by
162 posts views Thread by Richard Heathfield | last post: by
9 posts views Thread by d.adamkiewicz | last post: by
67 posts views Thread by bluejack | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.