how has C bitten you?

Brian Jones qwerty at drutx.UUCP
Mon Aug 5 15:53:55 AEST 1985


> 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



More information about the Comp.lang.c mailing list