snwprintf - standard

G

Googler

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.
 
M

Michael B Allen

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

swprintf declaration inconsistencies? 3
c16rtomb example wrong? 0
wcstombs() problem 16
Integer Overflow 121
string to int 5
Minimum Total Difficulty 0
wcslen function 2
Can't solve problems! please Help 0

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top