[pcre-dev] [Bug 1049] Add support for UTF-16

Page principale
Supprimer ce message
Auteur: Zoltan Herczeg
Date:  
À: pcre-dev
Anciens-sujets: [pcre-dev] [Bug 1049] New: Add support for UTF-16
Sujet: [pcre-dev] [Bug 1049] Add support for UTF-16
------- You are receiving this mail because: -------
You are on the CC list for the bug.

http://bugs.exim.org/show_bug.cgi?id=1049




--- Comment #24 from Zoltan Herczeg <hzmester@???> 2011-11-15 11:34:03 ---
(In reply to comment #20)
> (In reply to comment #15)
> > > By the way, does anyone know a clever way of compile time endianness check?
> >
> > Don't you just set up an int and then cast a pointer to it as char * and
> > then look at the bytes?
> >
> I've found that using pointer casting can cause some ugly compiler warnings
> (mind you, I was dealing with doubles at the time). A cleaner way is using a
> union:
>
> static const union { int i; char c; } order = { 1 }; /* initialisation assigns
> first union member */
>
> You can then simply check:
>
> if (order.c == 1) {
>    /* little endian */
> } else {
>    /* big endian */
> }

>
> Both gcc and llvm/clang recognize this correctly and optimize out the unused
> case.


Thank you for the idea. I am not sure what other compilers do, so we probably
need to introduce a macro, which is doing the stuff above by default. Still it
allows different implementation if needed.


--
Configure bugmail: http://bugs.exim.org/userprefs.cgi?tab=email