[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: attributed string Macro in TalkSoup
From: |
Matt Rice |
Subject: |
Re: attributed string Macro in TalkSoup |
Date: |
Tue, 10 Sep 2013 17:01:08 -0700 |
On Tue, Sep 10, 2013 at 4:31 PM, Riccardo Mottola
<riccardo.mottola@libero.it> wrote:
> Hi,
>
>
> Wolfgang Lux wrote:
>>
>> Riccardo Mottola wrote:
>>
>>> do you see anything wrong with this macro?
>>>
>>> #define S2AS(_x) ( (_x) ? [[[NSAttributedString alloc] initWithString:
>>> (_x)] autorelease] : nil )
unrelated to the warnings, but one issue with this macro is that it
evaluate _x twice, should x contain side effects or message sends,
message sends will be invoked twice, side effects applied twice e.g.
S2AS(foo[i++]) would increment i twice
generally this is something to be avoided, one potential way to avoid
it would be by putting categories on the class of _x e.g. -[_xclass
attributedString], message to nil would return nil and so there should
be no need to evaluate _x multiple times anymore.