%x vs. %X vs %lx (was: NTP 3.4.1.6 porting problems +FIX)

Steve Summit scs at adam.pika.mit.edu
Sat Jul 29 16:08:30 AEST 1989


In article <34005 at wlbr.IMSD.CONTEL.COM> sms at wlv.imsd.contel.com (Steven M. Schultz) writes:
>	In porting NTPD and friends I uncovered a number of
>	problems, all related to being on a machine where
>	sizeof (int) != sizeof (long).  Using %X to print
>	the value of ntohs()...

The old code was doubly wrong; %X shouldn't be used to print a
long.  %X, %D, %U, and %O no longer imply a long argument; long
arguments are uniquely indicated with the 'l' modifier: %lx,
%ld, %lu, and %lo.  %X now means "hexadecimal, but use ABCDEF
instead of abcdef."  The other three are undefined.  (The code
presumably worked to print the long result of ntohs() on a
machine with sizeof(int) == sizeof(long).)

                                            Steve Summit
                                            scs at adam.pika.mit.edu



More information about the Comp.bugs.2bsd mailing list