C/C++ Programmer's Guide (G06.25+)
HP C Implementation-Defined Behavior
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
A-13
G.5 Common Extensions
Wide characters are integers of type wchar_t, defined in the headers stddef.h
and stdlib.h as:
typedef unsigned short wchar_t;
Such an integer can represent distinct codes for each of the characters in the
extended character set. The codes for the basic C character set have the same
values as their single-character forms.
Relationship Between Multibyte and Wide Characters:
•
Multibyte characters are convenient for communicating between the program and
the outside world.
•
Wide characters are convenient for manipulating text within a program.
•
The fixed size of wide characters simplifies handling both individual characters and
arrays of characters.
MB_CUR_MAX Macro:
•
The MB_CUR_MAX macro specifies the maximum number of bytes used in
representing a multibyte character in the current locale (category LC_CTYPE). The
MB_CUR_MAX macro is defined in the header STDLIBH as:
#define MB_CUR_MAX 2
Conversion Functions:
•
The run-time library functions that manage multibyte characters and wide
characters are:
Alignment Issues
Native C and C++ considers objects of integral types to exist only on word boundaries.
Consequently, it is invalid to use an odd-byte address to access such an object. On
TNS/R or TNS/E systems, the results of using an integer type extended pointer
containing an odd-byte address are undefined. The code might continue executing or
trap. Therefore, it is important for you to ensure that all extended pointers contain
addresses that are even except for pointers to char. Extended pointers are those of
type long int or those of type int with the 32-bit (wide) data model in effect, in
which case an int is represented by 32 bits.
Function Description
mblen() Determines the length of a multibyte character.
mbtowc() Converts a multibyte character to a wide character.
wctomb() Converts a wide character to a multibyte character.
mbstowcs() Converts a string of multibyte characters to a string of wide characters.
wcstombs() Converts a string of wide characters to a string of multibyte characters.