home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!haven.umd.edu!darwin.sura.net!wupost!gumby!yale!yale.edu!ira.uka.de!gmd.de!Germany.EU.net!mcsun!news.funet.fi!hydra!klaava!wirzeniu
- From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
- Newsgroups: comp.lang.c
- Subject: Re: The %lf format specifier.
- Message-ID: <1992Nov6.201125.8252@klaava.Helsinki.FI>
- Date: 6 Nov 92 20:11:25 GMT
- References: <1992Oct31.163810.8497@alf.uib.no>
- Organization: University of Helsinki
- Lines: 37
-
- yngvar@imr.no (Yngvar Foelling) writes:
- >My question is: Is the %lf specifier really illegal in printf?
-
- It is definitely non-standard.
-
- >In that case, why _does_ the standard define specifiers like %hd for
- >short, when short is always expanded to int?
-
- What happens is that the short value is promoted to an int before the
- function is called, but the function converts it back before printing it
- out. This has implications for at least the u, o, X, and x formats,
- where the value is actually converted to an unsigned. For example, if
- you pass -(short)1 as the argument (which is an OK thing to do), the
- function gets -1 (a signed int) and convertes it to an unsigned short.
- If it couldn't convert it to short, but had to use int, and if ints are
- longer than shorts, the value printed out would be different.
-
- Try this on a machine with ints that are larger than shorts:
-
- printf("%x\n", -1);
- printf("%hx\n", -1);
-
- For example, on a two's complement machine with 16-bit shorts and 32-bit
- longs, the output is:
-
- ffffffff
- ffff
-
- If there were no %hx, it wouldn't be possible to obtain the latter
- output.
-
- I have no idea why %hd exists, though, unless it is because of
- orthogonality.
-
- --
- Lars.Wirzenius@helsinki.fi (finger wirzeniu@klaava.helsinki.fi)
- MS-DOS, you can't live with it, you can live without it.
-