對printf的單次呼叫可以列印的值的數量有限制嗎?
printf列印的值是否取決於為特定程式分配的記憶體,還是可以繼續列印值?
C標準記錄編譯器為函式呼叫接受的最小引數數量:
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 arguments in one function call
-
…
因此,您應該能夠在初始格式字串之後傳遞至少126個值到printf,假設格式字串被正確構造並與後面的實際引數保持一致.
如果格式字串是一個字串文字,則該標準保證編譯器可以處理長度至少為4095個位元組的字串文字,源行長至少為4095個字元.您可以使用字串連線來分割多個源行上的文字.如果您使用char陣列作為格式字串,則不存在此類限制.
printf系列功能的唯一環境限制是:
The number of characters that can be produced by any single conversion shall be at least 4095
這使得格式?000d的行為最好由實現定義,但是標準並不要求任何東西.
因此,相容的編譯器/庫組合應該至少為printf接受126個值,無論您的環境是否允許更多的引數可以由實現定義並記錄在案,但不能由標準保證.
http://stackoverflow.com/questions/35671020/is-there-a-limit-on-the-number-of-values-that-can-be-printed-by-a-single-call-of