使用gcc 4.4.1在Ubuntu Karmic上编译一些遗留C代码时,我收到以下警告
警告是:
src / filename.c:385:警告:'0'标志 用精度和'%i'忽略 gnu_printf格式
导致警告发出的片段是:
char buffer[256] ;
long fnum ;
/* some initialization code here ... */
sprintf(buffer, "F%03.3i.DTA", (int)fnum); /* <- warning emitted here */
我想我理解这个警告,但我想在这里查看我是否正确,以及解决这个问题的(明确的)正确方法。
答案 0 :(得分:3)
来自printf(3)
手册页:
0 The value should be zero padded. For d, i, o, u, x, X, a, A, e,
E, f, F, g, and G conversions, the converted value is padded on
the left with zeros rather than blanks. If the 0 and - flags
both appear, the 0 flag is ignored. If a precision is given
with a numeric conversion (d, i, o, u, x, and X), the 0 flag is
ignored. For other conversions, the behavior is undefined.
因此,您可以使用零填充或最小位数,但不能同时使用两者。