[Numpy-discussion] Changeset 6557

David Cournapeau cournape@gmail....
Sat Mar 7 12:02:03 CST 2009


On Sun, Mar 8, 2009 at 2:52 AM, Charles R Harris
<charlesr.harris@gmail.com> wrote:
>
>
> On Sat, Mar 7, 2009 at 11:41 AM, David Cournapeau <cournape@gmail.com>
> wrote:
>>
>> On Sat, Mar 7, 2009 at 6:01 AM, Charles R Harris
>> <charlesr.harris@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'};
>> >
>
> Yes, but look at the second version. It does essentially what your macro
> does, only uses 1,2,3,4 instead of 'A','B','C','D'.

Yes, it is the same thing, so I don't see the point of changing :) The
const union does not help, BTW. At least with gcc on mac os x, as long
as you have an if to test bint.c[0], it does not look smart enough to
detect all this is constant. But then, it is not like this function
benefits from any optimization anyway - it is only used at import
time, and the function call is likely to be the most costly part
anyway.

David


More information about the Numpy-discussion mailing list