Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

c - printf/fprintf maximum size according to c99

The C99 standard says:

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

Does it mean that the maximum size is 4095 if yes why its says "at least"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You've found one of the more annoying aspects of the C language specifications. They don't usually say what a maximum is. Instead, they'll usually say what the smallest allowed value for a maximum is.

They recognized that different hardware / compiler / linker environments have different restrictions, so they left most of the limits up to the individual tool authors. However, they wanted to provide some amount of portability between environments, so they specified the lowest values that maximums could take.

This is how we got restrictions like only the first 8 characters of identifiers being taken into account when disambiguating symbols -- they didn't want to force any implementor to deal with longer identifiers, so they said the "least maximum" length was 8.

It's the same story here -- they wanted programmers to be able to use decent-sized conversion, but recognized some platforms may not be able to handle huge conversions -- so they put in place a size large enough for most programmers to never know about the limit, but small enough that some implementations can do only the minimum and still be compliant.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...