On Sat, Mar 7, 2009 at 6:01 AM, Charles R Harris
<charlesr.har...@gmail.com> wrote:
> Hi David,
>
> Currently,
>
> bint.i = __STR2INTCST("ABCD");
>
> It is probably more portable to just initialize the union
>
>     union {
>         char c[4];
>         npy_uint32 i;
>     } bint = {'A','B','C','D'};
>

Ah, tempting, right ? It does not work. It has exactly the same
problem as multibyte initialization, that is it is undefined, or at
least there are some platforms where depending on the compiler, the
result will be different.

Mac OS X makes this easy to test (on x86). With your initialization
scheme, bint.c[0] is 'A' whether I compile with -arch x86 or -arch ppc
(mac os x can run ppc code in intel thanks to rosetta, a JIT ppc vm).
With mine, it does what is expected ('A' on big endian - ppc, and 'D'
on little endian).

cheers,

David
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to