Re: [PATCH 1/2] add macro REALLOCARRAY
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 16, 2014, 19:27 UTC
- Message-ID
- <xmqqy4tj1i39.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <541886D5.8060202@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 16 quoted lines
> Am 16.09.2014 um 05:04 schrieb Junio C Hamano: >> On Sun, Sep 14, 2014 at 9:55 AM, René Scharfe <l.s.r@web.de> wrote: >>> +#define REALLOCARRAY(x, alloc) x = xrealloc((x), (alloc) * sizeof(*(x))) >> >> I have been wondering if "x" could be an expression that has an operator >> that binds weaker than the assignment '='. That may necessitate the LHS >> of the assignment to be somehow marked as bound the tightest, i.e. >> >> #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), (alloc) * sizeof(*(x))) >> >> Or am I being overly silly? > > ALLOC_GROW did well without that. I can't think of a good use case > for a complex expression on the right-hand side. That said, I think I > still have a spare matching pair of parentheses lying around here > somewhere, so let's play it safe and use them. :)
Yeah, as long as (any) is still an lvalue for any lvalue for everybody's compiler, (x) = ... expression ... is safer, but taking cue from ALLOC_GROW(), I would say I was probably being slightly overly silly.