string length limitation of printf

Discussion in 'C Programming' started by Seong-Kook Shin, Jan 28, 2005.

  1. 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/
     
    Seong-Kook Shin, Jan 28, 2005
    #1
    1. Advertising

  2. Seong-Kook Shin

    Mike Wahler Guest

    "Seong-Kook Shin" <> wrote in message
    news:ctc3b4$cvl$...
    > 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
     
    Mike Wahler, Jan 28, 2005
    #2
    1. Advertising

  3. Seong-Kook Shin

    Mike Wahler Guest

    "Mike Wahler" <> wrote in message
    news:uJgKd.7890$...

    > 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
     
    Mike Wahler, Jan 28, 2005
    #3
  4. Seong-Kook Shin

    pete Guest

    Mike Wahler wrote:
    >
    > "Seong-Kook Shin" <> wrote in message
    > news:ctc3b4$cvl$...
    > > 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
     
    pete, Feb 4, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam
    Replies:
    3
    Views:
    14,146
    Karl Seguin
    Feb 17, 2005
  2. Brad
    Replies:
    4
    Views:
    5,396
    Jim Higson
    Apr 5, 2006
  3. Replies:
    5
    Views:
    677
    John W. Kennedy
    Jan 11, 2007
  4. TT
    Replies:
    1
    Views:
    315
    Jarkko Torppa
    Jun 10, 2008
  5. Al Knowles

    Do webservices have a parameter length limitation?

    Al Knowles, Aug 29, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    385
    Al Knowles
    Aug 29, 2003
Loading...

Share This Page