开发者

warning: '0' flag ignored with precision and ‘%i’ gnu_printf format

I am getting the following warning when compiling some legacy C code on Ubuntu Karmic, using gcc 4.4.1

The warning is:

src/filename.c:385: warning: '0' flag ignored with precision and ‘%i’ gnu_printf format

The snippet which causes the warning to be emitted is:

 char     bu开发者_StackOverflow中文版ffer[256] ;
 long     fnum ;
 /* some initialization code here ... */
 sprintf(buffer, "F%03.3i.DTA", (int)fnum);  /* <- warning emitted here */

I think I understand the warning, but I would like to check in here to see if I am right, and also the (definite) correct way of resolving this.


From the printf(3) man page:

   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.

So you can have either a zero fill or a minimum number of digits, but not both.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜