Talk:c/string/multibyte/mbrtoc32

Example
Please forgive me for not seeing the obvious, but how does the while loop in the example terminate? Inserting the statement as the first statement in the body of the while loop exposes the value of  that went into the function  and the return code  that came from it. At the start of the "final" iteration of the loop, both pointers and  target the same null terminating character in the original string. So, the third argument in the function call is zero, and the return code is -2, causing an infinite loop. On the other hand, adding one to the expression seems to allow  to see the null character, return zero, and the modified example avoids the infinite loop. Newatthis (talk) 07:36, 15 January 2017 (PST)
 * looks like you're right, the loop was assuming the terminating zero is part of the string (being a port of the C++ example), and so it needed strlen + 1. --Cubbi (talk) 09:17, 15 January 2017 (PST)
 * Many thanks. Newatthis (talk) 03:16, 16 January 2017 (PST)

state initialization
In the given code example, it took me a while to realize that state is implicitly 0-initialized because it is a global variable. I think it'd be better to make it a local variable and initialize it explicitly, unless I'm missing something ?

Babbage (talk) 12:12, 10 May 2022 (PDT)


 * I agree with that, edited as such --Ybab321 (talk) 04:42, 17 May 2022 (PDT)