snwprintf - standard

Discussion in 'C Programming' started by Googler, Aug 22, 2003.

  1. Googler

    Googler Guest

    Sorry about my mistake in subject.
    I was asking about swprintf not snwprintf.

    Anyway one more question.
    int swprintf(wchar_t * restrict s,size_t n,const wchar_t * restrict
    ormat, ...);

    The swprintf function returns the number of wide characters written in
    the array, not counting the terminating null wide character, or a neg
    ative value if an encoding error occurred or if n or more wide
    characters were requested to be written.

    So here count is a size_t & return is an int.

    So what happens if I pass in a value greater than that can be fitted
    into a signed int - won't the return value get totally broken in that
    case ?


    i.e. I pass in

    wchar_t s[INT_MAX + 10];
    swprintf(s,INT_MAX + 5, somereallybigbuffer);

    In this case, my buffer s is big enough to write INT_MAX + 5, however,
    swprintf will not be able to return INT_MAX + 5 because it returns an
    int.
     
    Googler, Aug 22, 2003
    #1
    1. Advertising

  2. On Fri, 22 Aug 2003 14:53:00 -0400, Googler wrote:

    > int swprintf(wchar_t * restrict s,size_t n,const wchar_t * restrict
    > ormat, ...);
    >
    > So here count is a size_t & return is an int.
    >
    > So what happens if I pass in a value greater than that can be fitted
    > into a signed int - won't the return value get totally broken in that
    > case ?


    Yes I suppose it will but you would never operate on a string with more
    elements than that which could be represented by an int. If an int is 2
    bytes you're probably working on a little DSP chip or something so your
    strings are probably not going to be more than 32,000 elements. If you're
    working on a machine with 24 bit integers your strings would have to be
    something like 8 million elements long. It's just never going to happen.

    Mike
     
    Michael B Allen, Aug 23, 2003
    #2
    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. Googler

    snwprintf - standard

    Googler, Aug 22, 2003, in forum: C Programming
    Replies:
    1
    Views:
    3,377
    Sven Semmler
    Aug 22, 2003
  2. Googler

    snwprintf - standard

    Googler, Aug 22, 2003, in forum: C Programming
    Replies:
    2
    Views:
    776
    Michael B Allen
    Aug 22, 2003
  3. Googler

    Re: snwprintf - standard

    Googler, Aug 22, 2003, in forum: C Programming
    Replies:
    1
    Views:
    401
  4. steve.leach

    How standard is the standard library?

    steve.leach, Apr 18, 2005, in forum: Python
    Replies:
    1
    Views:
    404
    Christos TZOTZIOY Georgiou
    Apr 18, 2005
  5. funkyj
    Replies:
    5
    Views:
    1,144
    funkyj
    Jan 20, 2006
Loading...

Share This Page