Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > string length limitation of printf

Reply
Thread Tools

string length limitation of printf

 
 
Seong-Kook Shin
Guest
Posts: n/a
 
      01-28-2005
C FAQ Q 13.2 says that sprintf() is guaranteed to work only for n <= 509:

sprintf(dest, "%.*s", n, source);

Does 509 appear in any C standard? If not, where it came from?
I looked over C99 (ISO/IEC 9899:1999) but didn't find yet.

If that limitation is old standard (perhaps ANSI?), does it limit the total
length of the string that sprintf() would print, or just for one '%s'?

I heard that on some old system does have a limitation on the total output
length of printf() family. If this limitation is not covered by (any) C
standard,
where can I get the information? (perhaps POSIX?)

Thanx.

--
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://www.cinsk.org/cfaqs/
 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      01-28-2005

"Seong-Kook Shin" <(E-Mail Removed)> wrote in message
news:ctc3b4$cvl$(E-Mail Removed)...
> C FAQ Q 13.2 says that sprintf() is guaranteed to work only for n <= 509:


That's funny, I see that Q 13.2 is about 'strncpy()' function.

>
> sprintf(dest, "%.*s", n, source);
>
> Does 509 appear in any C standard? If not, where it came from?
> I looked over C99 (ISO/IEC 9899:1999) but didn't find yet.


> If that limitation is old standard (perhaps ANSI?), does it limit the

total
> length of the string that sprintf() would print, or just for one '%s'?
>
> I heard that on some old system does have a limitation on the total output
> length of printf() family. If this limitation is not covered by (any) C
> standard,
> where can I get the information? (perhaps POSIX?)


From the 1999 standard:
--------------------------------------------------------------
7.19.6.1 The fprintf function

Returns

14 The fprintf function returns the number of characters
transmitted, or a negative value if an output or encoding
error occurred.

Environmental limits

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



From the 1989 standard:
--------------------------------------------------------------
4.9.6.1 The fprintf function

Returns

The fprintf function returns the number of characters transmitted,
or a negative value if an output error occurred.

"Environmental limit"

The minimum value for the maximum number of characters produced by
any single conversion shall be 509.
--------------------------------------------------------------



-Mike









 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      01-28-2005
"Mike Wahler" <(E-Mail Removed)> wrote in message
news:uJgKd.7890$(E-Mail Removed) ink.net...

> From the 1999 standard:
> --------------------------------------------------------------
> 7.19.6.1 The fprintf function
> -Mike


Anticipating a possible objection that you asked about 'sprintf()'
rather than 'fprintf()':

7.19.6.6 The sprintf function

Description

2 The sprintf function is equivalent to fprintf, except that the
output is written into an array (specified by the argument s)
rather than to a stream. A null character is written at the end
of the characters written; it is not counted as part of the
returned value. If copying takes place between objects that
overlap, the behavior is undefined.

Returns

3 The sprintf function returns the number of characters written in
the array, not counting the terminating null character, or a neg-
ative value if an encoding error occurred.

-Mike


 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      02-04-2005
Mike Wahler wrote:
>
> "Seong-Kook Shin" <(E-Mail Removed)> wrote in message
> news:ctc3b4$cvl$(E-Mail Removed)...
> > C FAQ Q 13.2 says that sprintf()
> > is guaranteed to work only for n <= 509:

>
> That's funny, I see that Q 13.2 is about 'strncpy()'
> function.
>
> >
> > sprintf(dest, "%.*s", n, source);
> >
> > Does 509 appear in any C standard? If not, where it came from?
> > I looked over C99 (ISO/IEC 9899:1999) but didn't find yet.

>
> > If that limitation is old standard (perhaps ANSI?),
> > does it limit the total
> > length of the string that sprintf() would print,
> > or just for one '%s'?
> >
> > I heard that on some old system does have
> > a limitation on the total output
> > length of printf() family. If this limitation
> > is not covered by (any) C
> > standard,
> > where can I get the information? (perhaps POSIX?)

>
> From the 1999 standard:
> --------------------------------------------------------------
> 7.19.6.1 The fprintf function
>
> Returns
>
> 14 The fprintf function returns the number of characters
> transmitted, or a negative value if an output or encoding
> error occurred.
>
> Environmental limits
>
> 15 The number of characters that can be produced by any single
> conversion shall be at least 4095.
> --------------------------------------------------------------
>
> From the 1989 standard:
> --------------------------------------------------------------
> 4.9.6.1 The fprintf function
>
> Returns
>
> The fprintf function returns the number of characters transmitted,
> or a negative value if an output error occurred.
>
> "Environmental limit"
>
> The minimum value for the maximum number of characters produced by
> any single conversion shall be 509.
> --------------------------------------------------------------


There's also an environmental limit on line length.

N869
7.19.2 Streams
Environmental limits
[#7] An implementation shall support text files with lines
containing at least 254 characters, including the
terminating new-line character.

--
pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
65K length limitation in MySQLdb? TT Python 1 06-10-2008 05:53 AM
String exceeding length - Getting absolute string length james.w.appleby@gmail.com Java 5 01-11-2007 12:07 AM
HELP: Request String Length Limitation? Brad HTML 4 04-05-2006 09:00 AM
left(string, length) or right(string, length)? Sam ASP .Net 3 02-17-2005 12:01 PM
Do webservices have a parameter length limitation? Al Knowles ASP .Net Web Services 0 08-29-2003 11:32 AM



Advertisments