Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mcgill-vision.UUCP Path: utzoo!linus!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: net.lang.c Subject: Re: how has C bitten you? Message-ID: <109@mcgill-vision.UUCP> Date: Mon, 12-Aug-85 18:14:00 EDT Article-I.D.: mcgill-v.109 Posted: Mon Aug 12 18:14:00 1985 Date-Received: Wed, 14-Aug-85 23:43:13 EDT References: <243@ecrhub.UUCP> Organization: McGill University, Montreal Lines: 38 > scanf("%D %F", long, double); > scanf("%ld %lf", long, double); [should be &long, &double in both cases] > vs. > printf("%ld %f", long, double); > Why no %F or %D on printf? Good question. Belongs there. So don't use it in scanf and there's no problem. > And why %lf vs %f? fun! Disclaimer first: What I say here is based on my hacking on a VAX. Lots of my comments may well be invalid elsewhere. The C compiler produces exactly the same code for printf(format,long,double) as printf(format,long,float) Remember in K&R how all floats are converted to doubles all the time? This also happens in function calls. Printf may support %lf; I haven't checked. But it would necessarily be treated exactly the same as %f because of this extension. Scanf does not have the same problem (feature?) because you pass a pointer, you don't pass the value directly. By the way (this is very VAX-dependent), you can scanf into a double and tell scanf it's a float (use %f rather than %lf). This works because the first 4 bytes of a double form a valid float. The extra precision will be unchanged, but for user input, the data generally isn't that precise anyway. -- der Mouse System hacker and general troublemaker CVaRL, McGill University Hacker: One responsible for destroying / Wizard: One responsible for recovering it afterward