Passing too many arguments to printf

前端 未结 5 989
不思量自难忘°
不思量自难忘° 2020-11-30 10:56

Any C programmer who\'s been working for more than a week has encountered crashes that result from calling printf with more format specifiers than actual argume

5条回答
  •  温柔的废话
    2020-11-30 11:24

    Online C Draft Standard (n1256), section 7.19.6.1, paragraph 2:

    The fprintf function writes output to the stream pointed to by stream, under control of the string pointed to by format that specifies how subsequent arguments are converted for output. If there are insufficient arguments for the format, the behavior is undefined. If the format is exhausted while arguments remain, the excess arguments are evaluated (as always) but are otherwise ignored. The fprintf function returns when the end of the format string is encountered.

    Behavior for all the other *printf() functions is the same wrt excess arguments except for vprintf() (obviously).

提交回复
热议问题