Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 (Denver Mods 7/26/84) 6/24/83; site drutx.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!drutx!qwerty From: qwerty@drutx.UUCP (Brian Jones) Newsgroups: net.lang.c Subject: Re: how has C bitten you? Message-ID: <55@drutx.UUCP> Date: Mon, 5-Aug-85 01:53:55 EDT Article-I.D.: drutx.55 Posted: Mon Aug 5 01:53:55 1985 Date-Received: Tue, 6-Aug-85 08:44:54 EDT References: <302@brl-tgr.ARPA>, <4081@alice.UUCP> <243@ecrhub.UUCP> Organization: AT&T Information Systems, Denver Lines: 42 > One of my all time favourites is the non-orthagonality between > scanf and printf. Especially the following: > > scanf("%D %F", long, double); or > scanf("%ld %lf", long, double); > vs. > printf("%ld %f", long, double); > > Why no %F or %D on printf? > And why %lf vs %f? fun! > > -- > -------------------------------------------------------------------------- > David M. Haynes > Exegetics Inc. > ..!utzoo!ecrhub!david > > "I am my own employer, so I guess my opinions are my own and that of > my company." scanf can be given a pointer to any data type: char (string) int, long, float, double; When you put arguments on stack, expansion rules are followed. char => int float => double So, printf can never get a float as an argument, it always gets a double. Therefore, %lf or %F are meaningless to printf. Note that printf does support %d and %ld, and will happily screw up if there is a disagreement between the args and their specification in the format string. ie. %d given a long arg, or %ld given a short. (machine dependent!!). -- Brian Jones aka {ihnp4,}!drutx!qwerty @ AT&T-IS