是否有可以由printf的单一调用打印值的数量有限制吗? [英] Is there a limit on the number of values that can be printed by a single call of printf?

查看:258
本文介绍了是否有可以由printf的单一调用打印值的数量有限制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不依赖于分配给特定程序的内存printf的打印值的数量,也可以继续打印值?

Does the number of values printed by printf depend on the memory allocated for a specific program or it can keep on printing the values?

推荐答案

C标准记录的参数的最小数目编译器应该能够接受一个函数调用:

The C Standard documents the minimum number of arguments that a compiler should accept for a function call:

5.2.4.1 C11翻译限制

C11 5.2.4.1 Translation limits

的执行应能够翻译和执行包含以下范围的每一个的至少一个实例的至少一个程序:

The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits:


      
  • ...

  • ...

127论点一个函数调用

127 arguments in one function call

...

因此​​,你应该能够在初始格式字符串后,通过至少126值的printf ,假设格式字符串正确构造,并与实际参数一致,即随之而来。

Therefore, you should be able to pass at least 126 values to printf after the initial format string, assuming the format string is properly constructed and consistent with the actual arguments that follow.

如果格式字符串是一个字符串,该标准保证了编译器可以处理字符串文字至少有4095字节长,和源线长度至少为4095个字符。您可以使用字符串连接分割文字上的多个源行。如果使用字符阵列格式字符串,没有这样的限制存在。

If the format string is a string literal, the standard guarantees that the compiler can handle string literals at least 4095 bytes long, and source lines at least 4095 characters long. You can use string concatenation to split the literal on multiple source lines. If you use a char array for the format string, no such limitation exists.

记载的的printf 系列函数的唯一环境的限制是这样的:

The only environmental limit documented for the printf family of functions is this:

这可以被任何单次转换生成的字符数应至少为4095

The number of characters that can be produced by any single conversion shall be at least 4095

这使得格式的行为%10000D 最好由实现定义,但该标准并不强制任何东西。

This makes the behavior of format %10000d at best defined by the implementation, but the standard does not mandate anything.

一个兼容的编译器/库组合因此应该接受的printf 至少126值,您的环境是否允许更多的参数可以由实现来定义和记录正因为如此,但不是由标准保证。

A compliant compiler/library combination should therefore accept at least 126 values for printf, whether your environment allows even more arguments may be defined by the implementation and documented as such, but is not guaranteed by the standard.

这篇关于是否有可以由printf的单一调用打印值的数量有限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆