"Me" <> wrote in message
news

ia.com...
> I am trying to compile some code Ive gotten from another and
> I know I need a 16 bit unicode string, for he passes the pointer to
> functions
> that take a (uint16 *), however there are initializations that look like
> this.
>
> typedef unsigned short int ucs2_char;
The correct type for UCS2 characters is wchar_t. Fix the code to use the
correct type.
> static const ucs2_char form_feed[] = L"\f";
>
> The above like in gcc give me the compiler error: 'invalid initializer'
>
> When I change it to the following, everything works fine.
>
> static const ucs2_char *form_feed = L"\f";
>
> What is up with this error?
What's up is you're using the wrong type; L"\f" is a wide character literal,
not an array of unsigned short ints. The latter should give you a warning
as well, since you're doing an implicit conversion between wchar_t[] and
unsigned short*, but your compiler may not be smart enough to catch that.
typedef unsigned short int ucs2_char;
static const ucs2_char form_feed[] = L"\f";
foo.c:2: warning: initialization from incompatible pointer type
typedef unsigned short int ucs2_char;
static const ucs2_char form_feed[] = L"\f";
foo.c:2: invalid initializer
#include <wchar.h>
static const wchar_t *form_feed = L"\f";
static const wchar_t form_feed[] = L"\f";
[ no compile warnings or errors ]
S
--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin