how has C bitten you?
David M. Haynes
david at ecrhub.UUCP
Thu Aug 8 03:30:05 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!
>>
>
>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
Yes, I did realize that, but (and this is where the show really starts..)
the problem I reported is one of NON-ORTHAGONALITY not implementation.
Your explanation is quite correct, but why should I (as a programmer)
have to worry about translation to stack? Why doesn't printf take
%F and %D and translate for me so that the orthagonality of the two
system calls (which are considered by most to be related functions)
is the same?
B.T.W. This originally was in response to the "How has C bitten you?" question
but has digressed at this point. Apologies and I'll mail further
discussion directly.
--
--------------------------------------------------------------------------
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."
More information about the Comp.lang.c
mailing list