Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!sdd.hp.com!mips!cs.uoregon.edu!ogicse!intelhf!ichips!inews!pima!bhoughto From: bhoughto@pima.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: missing ->= operator Message-ID: <4122@inews.intel.com> Date: 1 May 91 03:48:33 GMT References: <9104291641.AA00534@dutiaa.tudelft.nl> <1991Apr30.165110.4165@unhd.unh.edu> Sender: news@inews.intel.com Organization: Intel Corp, Chandler, AZ Lines: 54 In article <1991Apr30.165110.4165@unhd.unh.edu> jwm712@unhd.unh.edu (Jonathan W Miner) writes: >In article <9104291641.AA00534@dutiaa.tudelft.nl> schuller@DUTIAA.TUDELFT.NL (Schuller Schuller Oijen) writes: >>What you do quite often is : mygodptr = mygodptr->next; >>But the ->= operator is missing! You cannot do mygodptr ->= next; ! Although it would be nice not to have to type the structure-pointer name twice on the same line, the current situation is syntactically consistent. What's happening with the assignment operators is always (lvalue) (arithmetic-binary-operator)= (rvalue); in a structure, the member-names are not rvalues, and `->' is not an arithmetic-binary-operator (that's "binary" as in "with two operands" rather than "with binary-data-typed operands", and while it is always thus binary it is never arithmetic). The truly easiest (and IMHO cleanest) way to handle this is: #define next(x) ((x)->next) ... struct foo { ... ; struct foo *next; } *bar; ... bar = next(bar); and to _always_ use the word `next' as the member-name for the next member of a singly-linked list. Similar conventions hold for adding a `prev' member for a doubly-linked list, and a `name' member for structures that have names. Even if the structures are designed to be in multiple lists, you will often want to keep a list of them in the order in which you allocate them, so that if an elegant method of searching for a particular struct can't be found, you can always go to the first-allocated struct and roll down the allocation-list. >Now for my question: how do the below operators compare speedwise? > a++; inc a; > a += 1; add2 1,a; > a = a + 1; add3 1,a,a; Looks like you compile with the brakes (the -g flag) on. --Blair "Ert!" -Matt Feazell, "CynicalMan"