[unixODBC-support] Unicode and Wide Char strings

Neha Avasthy neha.avasthy at gmail.com
Tue Oct 19 10:43:53 BST 2010


To add to this , In the example below

_T("SELECT NULL FROM DUAL"); expands to
L"SELECT NULL FROM DUAL";

Thanks
-Neha



On Tue, Oct 19, 2010 at 3:10 PM, Neha Avasthy <neha.avasthy at gmail.com>wrote:

> Hi ,
>
> I have a basic question w.r.t wide char literals. In the platforms I am
> working on WIDE chars are of size 2 bytes however the L"string" literals are
> of size wchar_t which is essentially 4 bytes.
>
> My application however expects UTF16 and thats why to make the following
> assignment work in the code
>
> TCHAR    pSql[] = _T("SELECT NULL FROM DUAL");
>
> typedef signed short        TCHAR;
> typedef long int        wchar_t;
>
> I am using the -fshort_wchar flag in the compile line .
>
> The gcc compiler handles L as wchar_t string where wchar_t is of 2 bytes on
> Windows and of 4
> bytes on Unix. As application expects the unicode strings to be of type
> unsigned short - 2 bytes so to convert 2 bytes unicode string the
> -fshort-wchar flag was added.
>
> However I figured out that
>
> -fshort-wchar seems to be a compiler hack only available with gcc.
> -fshort-wchar forces compiler (gcc) to treat wide charater literals as
> unsigned short. Thats not a  part of language standards anyways.
>
> This is has made my code non portable as equivalent flags are not available
> on other native compilers for Solaris, HPI and AIX.
>
> If I remove the -fshort_wchar flag from the compile line I get errors like
>
>  error: a value of type "long [22]" cannot be used to initialize an entity
> of type "TCHAR={signed short} []"
>     TCHAR    pSql[] = _T("SELECT NULL FROM DUAL");
>
> Can somebody tell me a way of dealing with this conversion. I have to
> ensure that the L"string" treatment is that of a 2 byte quantity.
>
> Thanks
> -Neha
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20101019/30ee65ac/attachment.html>


More information about the unixODBC-support mailing list