[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: prepare vasnprintf for Unicode strings
From: |
Jim Meyering |
Subject: |
Re: prepare vasnprintf for Unicode strings |
Date: |
Tue, 12 Jun 2007 20:52:46 +0200 |
Paul Eggert <address@hidden> wrote:
> Bruno Haible <address@hidden> writes:
>
>> Hey, 'int' is a flexible data type!
>
> I agree, though for this particular example I find the code
> easier to read if the test is ordered numerically, and if an
> if-then-else expression is used. So, instead of this:
>
> if (flags >= 16)
> type = TYPE_U32_STRING;
> else if (flags >= 8)
> type = TYPE_U16_STRING;
> else
> type = TYPE_U8_STRING;
>
> I might use something like the following, say.
>
> type = (flags < 8 ? TYPE_U8_STRING
> : flags < 16 ? TYPE_U16_STRING
> : TYPE_U32_STRING);
Same here. It's good that it avoids the repetition of "type =", too.
> Or if you prefer 'int' idioms I might do it this way:
>
> type = TYPE_U8_STRING + (8 <= flags) + (16 <= flags);
>
> as this is faster and smaller on many platforms.
For that one-liner, you must be playing devil's advocate or something,
since it'd make the code depend on TYPE_U16_STRING being one greater
than TYPE_U8_STRING, and TYPE_U32_STRING being one greater than
TYPE_U16_STRING. That's way too fragile for my taste.
Re: prepare vasnprintf for Unicode strings, Daniel Jacobowitz, 2007/06/11