missing ->= operator

Blair P. Houghton bhoughto at pima.intel.com
Wed May 1 13:48:33 AEST 1991


In article <1991Apr30.165110.4165 at unhd.unh.edu> jwm712 at unhd.unh.edu (Jonathan W Miner) writes:
>In article <9104291641.AA00534 at dutiaa.tudelft.nl> schuller at 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"



More information about the Comp.lang.c mailing list