Evaluation order of assignment.

Douglas C. Schmidt schmidt at bonnie.ics.uci.edu
Wed Aug 17 09:07:11 AEST 1988


Hi,

  Assume the following recursive type declaration for a linked
list:

struct list {
   int item;
   struct list *next;        
};

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)));
}
...

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 !! ;-)).

thanks,

   Doug Schmidt
--
Douglas Schmidt
"If our behavior is strict, we do not need fun." -Zippy th' Pinhead
"If our behavior is struct, we do not need defun." -Anon



More information about the Comp.lang.c mailing list