Re: cal: First day of the week

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

 



On Tue, Mar 10, 2009 at 01:15:14PM +0100, Samuel Thibault wrote:
> Karel Zak, le Tue 10 Mar 2009 13:09:22 +0100, a écrit :
> >  You need to use union:
> > 
> > 		int wfd;
> > 		union { unsigned int word; char *string; } val;
> > 		val.string = nl_langinfo(_NL_TIME_WEEK_1STDAY);
> > 
> > 		wfd = val.word;
> 
> That will only work with the gcc compiler, which allows to read a union
> field what you wrote in another.

 Hmm...

 C99, 6.5.2.3 Structure and union members

 82) If the member used to access the contents of a union object is
     not the same as the member last used to store a value in the object,
     the appropriate part of the object representation of the value is
     reinterpreted as an object representation in the new type as
     described in 6.2.6 (a process sometimes called "type punning"). This
     might be a trap representation.


> Shouldn't (int)(intptr_t)nl_langinfo()
> be just fine?

  That's readable and shorter :-) Fixed.

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux