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.car...@ucs.cam.ac.uk
University Computing Service,            Phone: (01223) 334502
New Museums Site, Pembroke Street,       Fax:   (01223) 334679
Cambridge UK. CB2 3QH.

Reply via email to