kyuupi wrote:
Limiting ourselves to C90 pre-amendment 1 interfaces,
TTBMK, mbtowc was only added to C with amendment 1 (in 1994).
So, limiting ourselves to interfaces that predate the amendment renders
the question moot.
is there a
guaranteed way to recover from an invalid character conversion
attempt? I'm unable to find anything. In other words, suppose we
have two strings, one starts with a bad character for the current
locale, and the other doesn't, what needs to be done below for the
assertion to pass?
According to the C99 standard (I don't have any other trustworthy
sources that mention the function), you can reset the conversion state
maintained by the mbtowc function with the call
mbtowc(NULL, NULL, 0)
The return value of this call indicates if the (current, locale
dependent) multi-byte character coding uses shift states or not.
I could not find any information that during the standardisation of C99
anything was changed in this area.
>
char bad[] = "<something>";
char ok[] = "<something else>";
void foo (void)
{
wchar_t wc;
if (mbtowc (&wc, bad, sizeof bad) == -1)
{
** what can be done here? **
assert (mbtowc (&wc, ok, sizeof ok) >= 0);
}
}
If there is nothing standardized, doesn't that render mbtowc and
friends somewhat useless in practice?
Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ:
http://www.comeaucomputing.com/learn/faq
c.l.c FAQ:
http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ:
http://www.parashift.com/c++-faq-lite/