Path: utzoo!attcan!uunet!husc6!uwvax!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Evaluation order of assignment. Message-ID: <13036@mimsy.UUCP> Date: 17 Aug 88 02:37:07 GMT References: <957@orion.cf.uci.edu> Distribution: na Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 33 In article <957@orion.cf.uci.edu> schmidt@bonnie.ics.uci.edu (Douglas C. Schmidt) writes: >Is the following always guaranteed to produce the "intended" result: > >struct list foo() >{ > struct list head; > > return(head->next = head = (struct list *) malloc(sizeof(struct list))); >} Aside from the fact that there are two `*'s missing, and that malloc can return NULL, the answer is no. >My intention is to create a dummy node in a circularly-linked list, >and assign the dummy node's next field to point to the head of >the list. Since assignment associates from right-to-left this >will alway work, right (cryptic style notwithstanding !! ;-)). Not so. If you must use cryptic style, try /* assuming emalloc() is declared, and is like malloc but never returns NULL: */ struct list *foo() { struct list *head; return (head = (struct list *)emalloc(sizeof *head), head->next = head); } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris