Testing printf

I would like to have a portable implementation of my application. However, I heard that there are some problems with printf from stdlib on some machines where it does not behave as intended. For example, when using the conversion specifier% f, then it may happen that on some architectures the printf implementation includes a decimal point on the output!

Now I wonder if there are, perhaps, some testing procedures that I could use to check the semantic correctness of the stdlib c implementation, in particular the printf routine. Maybe there are some good resources that indicate some problems when porting programs?

Thanks a lot Heinz

+5
source share
4 answers

I think the Postel Act ("to be conservative in what you do, be liberal in what you accept from others") also applies here. Do not write down your tests to require matching for each character, to consider an implementation printf()that will work.

Instead, make it a higher level; analyze the output of the text using printf()the expected data type and compare it with the value of this type.

Ie, if the print is "2.25", parse the text (using strtod()either the equivalent) and compare with the actual number 2.25, rather than the literal text string "2.25".

+4
source

, , . printf 100 , - , , .

+1

: sprintf() "".

- fprintf ( ).

, printf sprintf : .

0

All Articles