Four patches against 2.3.14

David Carter dpc22 at cam.ac.uk
Fri Mar 27 08:25:38 EDT 2009


On Fri, 27 Mar 2009, Bron Gondwana wrote:

> l->tail = l->tail->next = n;
>
> Is that _guaranteed_ to evaluate correctly?  It looks like someone
> being a smartarse to avoid writing:
>
> l->tail->next = n;
> l->tail = l->tail->next;

It's a fairly common idiom for managing linked lists in C.

Or at least I thought that it was a fairly common idiom: the only other 
obvious incidences I can find in Cyrus are sync_support.c, make_md5.c and 
make_sha1.c, which are probably all down to me. Smartarse.

'=' has right to left associativity (K&R second edition, page 53), so:

  a = b = c

evaluates as:

  a = (b = c)

But if you are happier with two or three lines of code, then go for it.

-- 
David Carter                             Email: David.Carter at ucs.cam.ac.uk
University Computing Service,            Phone: (01223) 334502
New Museums Site, Pembroke Street,       Fax:   (01223) 334679
Cambridge UK. CB2 3QH.


More information about the Cyrus-devel mailing list