Pointer incrementation and assignme

John Kallen jkl at csli.Stanford.EDU
Sat May 27 15:51:56 AEST 1989


In article <236100012 at mirror> root at mirror.TMC.COM writes:
>In reality
>the command a++ is just shorthand for a+=1 and a = a+1.  It was origionally
>made for lines like:
>
>	whatchamacallit = whatchamacallit + 1;
>
>Carnigan and Ritchie were programmers who didn't like to type.

Kernighan and Ritchie might be lazy typists, but there's another for
having += and ++ operators: I don't have it in front of me, but in the
Bible there was an example of a hairy expression like:

	yylval[yylval1[i]][yylval2[i]] = yylval[yylval1[i]][yylval2[i]] + 1;

which might very easily get corrupted inadvertently. Now,

	yylval[yyval1[i]][yylval2[i]] ++;

is not only shorter code, but *safer*, and above all MUCH clearer.
Useful little beasties, the assignment and the increment operators.

John.
_______________________________________________________________________________
 | |   |   |    |\ | |   /|\ | John Kallen           
 | |\ \|/ \|  * |/ | |/|  |  | PoBox 11215           Support gun control - 
 | |\ /|\  |\ * |\ |   |  |  | Stanford CA 94309     Kill an NRA member!
_|_|___|___|____|_\|___|__|__|_jkl at csli.stanford.edu___________________________



More information about the Comp.lang.c mailing list