Re: Struct vs Union on TCP/IP code



grocery_stocker wrote
(in article
<1130287766.285401.269310@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>):

> When finding the byte order, why would someone write like the
> following:
>
> union {
> short s;
> char c[sizeof(short)];
> } un;
>
> un.s = 0x0102;
>
> Why use a union over a structure?

Hard to know for sure without seeing the rest, but my guess is
to enable undefined behavior close by in the source code. :-)


--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw





.



Relevant Pages

  • Re: Would You Buy a Car from Chrysler?
    ... someone wants to be in a union, sure go for it, but don't drag me ... from the throne and it's decision to back one religion over others. ... The problem is what they do with that political power after they get it, ... Russia is an enigma - but Russians are a lot closer to Westernized ...
    (rec.autos.makers.chrysler)
  • Jack Straw: ENGLAND would lose by end of union.
    ... English matters when they represent Scottish constituencies. ... English MPs control all the money which Scotland receives - ... And power devolved is power retained, ... The outcome of a break-up of the union would be ...
    (soc.culture.scottish)
  • Re: Jack Straw: ENGLAND would lose by end of union.
    ... English MPs control all the money which Scotland receives - ... England constitutes 85% of the UK's population and 87% of its wealth. ... And power devolved is power retained, ... The outcome of a break-up of the union would be ...
    (uk.politics.misc)
  • Jack Straw: ENGLAND would lose by end of union.
    ... English matters when they represent Scottish constituencies. ... English MPs control all the money which Scotland receives - ... And power devolved is power retained, ... The outcome of a break-up of the union would be ...
    (uk.politics.misc)
  • Jack Straw: ENGLAND would lose by end of union.
    ... English matters when they represent Scottish constituencies. ... English MPs control all the money which Scotland receives - ... And power devolved is power retained, ... The outcome of a break-up of the union would be ...
    (uk.sport.football.clubs.rangers)