Date: Sat, 11 Aug 2001 11:44:36 -0700 From: Terry Lambert <tlambert2@mindspring.com> To: Rob <europax@home.com> Cc: "hackers@FreeBSD.ORG" <hackers@FreeBSD.ORG> Subject: Re: the =+ operator Message-ID: <3B757D14.B344931@mindspring.com> References: <3B73F0BC.548D40B3@home.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Rob wrote: > I've searched far and wide on search engines to find out what the =+ > operator does, to no avail. I'm porting some old code and found it. I > made a test program and compiled it with gcc, and all it appears to do > is the same as regular assignment. But I'm wondering if in some day > long ago, it mean't something else? Thanks, Rob. Before ANSI went and ruined everything (e.g. by adding prototypes instead of making the object file format store attribution data, and smarter linkers, because the committee was packed with compiler vendors who wanted to do good on benchmarks), there was K&R C. In K&R C, the one true C, token gathering was two pass; it did not ingnore whitespace for token seperation on the first pass, and ignored it on the second, when necessary to disambiguate unknown tokens. Historically, the =+ and =- operators were used in the original C compilers... I believe this was for weenies who were unfortunate enough to own HP calculators, but it was an anacronism even 1978, which is when my copy of "The C Programming Language" book was published (unfortunately, it's not a first printing); this is noted on page 212, where they also talk about no "=" initializers ("int i 1;" instead of "int i = 1;"; newer, dumber, compilers have a hard time disambiguating expressions like "int i (17+BOO);" from functions because of the one pass tokenizer, so this is not allowed by ANSI, either). I have used many compilers that took "=-", "=+", "=/", "=*", "=>>", etc., etc.. ANSI broke all this code when it stated that whitespace was always ignored (thus permitting compiler writers to do single pass token gathering using the "greedy" rule, which could be done with a single pass LALR parser, spitting out tokens when the next character could not possibly be part of the previous token). I have also seen the "/\" (max), "\/" (min), and "^^" (McCarthy XOR, moral symmetry for the McCarthy "||", "&&" operators), since the compilers that used them could put them into single machine instructions). My Manx Aztec C compiler for the IBM PC supports "=+" and "=-"; it is also smart enought to turn: "x * 10" into "x <<=2; x++; x<<=1", and the 68000 version was smart enough to realize the bus was 16 bits, not 32 bits, and so made "int" 16 bits on the 68000, but 32 bits on the 68k processors with 32 bit busses, resulting in single cycle transfer times for the data: most other compilers, (e.g. Lattice C), were stupid, and made int 32 bits to appease lousy programmers. Something to think about, for you "style" wonks who insist on "if ((a+=5))" instead of "if( a += 5)", not realizing that butting up the parenthesis left associatively is required to make some compilers work right, and the doubled parenthesis are just an editorial comment by the compiler writers about their preferred style of doing the test after the operation ("a += 5; if(a)"), coming from being assembly weenies, and not really something wrong, when they bitch about assignments in comparison statements. Kids these days: change the programmer to fit the machine... -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B757D14.B344931>