printf precision for strings

Ray Butterworth rbutterw at watmath.waterloo.edu
Sat Apr 27 00:36:51 AEST 1991


Consider the statement:
    printf("%.*s", len, data);
If len==0, this should produce no output.
But, what if data==(char*)0 too?

With some compilers it produces the string "<nil>".
(I realize this "<nil>" is just a silly way of avoiding dumping core
 or producing meaningless garbage, but that's not what I'm asking about.)

Shouldn't the precision of 0 guarantee that no output will occur,
or does using the bad pointer mean all bets are off?



More information about the Comp.std.c mailing list