wchar_t invalid initializer?

Greetings,

I was wondering if anyone has come across this before - or knows of a fix.

On all other non-QNX systems I’ve used, the following code compiles cleanly:

wchar_t foo[] = L"bar";

But on QNX this produces the compiler error: invalid initializer .

However, the following code DOES compile cleanly:

wchar_t *foo = L"bar";

Is it possible to compile the first version? Why would one version be supported over the other?

Thanks,
J

you are setting the pointer foo to address 'L"bar"?

(long) bar? ^^

Strange, I know. Yet the only way to achieve the desired effect.

I would much rather initialize an array[] with L"bar" instead of a pointer* but it seems the QNX compilers prefer the pointer notation, at least when it comes to wchar strings. Normal character arrays (of char) can be initialized using: char foo[] = “bar”; Just not wchar for some reason.

wchar_t is not a native ‘C’ or ‘C++’ type. Obviously it is created with a typedef. Find out how the typedef is defined and you may solve your problem.

As far as I can tell, it’s just a peculiarity of the QNX compiler. Perhaps it’s due to the old version of gcc (2.95), or perhaps someone overlooked that aspect.

Regardless, the wchar_t initializers exist on every other platform I’ve tested: Linux, BSD, Solaris, Windows - all work. So I must conclude that QNX is missing something, rather than me.

Try with GCC 3.3.5 or even the 4.2.1 beta.