Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!brl-adm!seismo!mimsy!chris From: chris@mimsy.UUCP Newsgroups: comp.lang.c Subject: Re: Order of evaluation Message-ID: <5956@mimsy.UUCP> Date: Wed, 25-Mar-87 12:21:39 EST Article-I.D.: mimsy.5956 Posted: Wed Mar 25 12:21:39 1987 Date-Received: Fri, 27-Mar-87 05:29:29 EST References: <4775@brl-adm.ARPA> <7779@utzoo.UUCP> <521@cpocd2.UUCP> <739@xanth.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 69 Summary: A matter of taste In article <739@xanth.UUCP> kent@xanth.UUCP (Kent Paul Dolan) writes: >... but C was an ugly language to begin with, because so much of >it doesn't parse the way it reads, due to _bizarre_ precedence results. Aside from the results of chongo's contests, I find most C code quite readable. The trouble areas are unusual declarations and `&' and `|' precedence: char *(*p[3])(); ... if (a & 1 == 0) /* is not what you expected */ The solution to the latter, of course, is (dramatic music) to Put In Many Many Parentheses. >Adding the unary plus, which, to anyone taught mathematics, >is a no-op, and making that the way to control the order of >evaluation, just makes an ugly language uglier. While it is a bit of a kludge, the fact that someone has written an explicit no-op should give you a hint that something special is going on. >ANSI should have mandated respecting parentheses for evaluation >order, so that code executes the way it reads. I do not agree. >This would break _no_ code, True enough. >and would let programmers' intuition be of some use .... Whose intuition? Certainly not mine. I expect the compiler to rip my parentheses to shreds. I confess to having written some floating point code in the past, aye, even in FORTRAN. I used multiple lines of statments to control evaluation order---even in FORTRAN, and even before I knew any other language except BASIC. (A humble start indeed!) #define input() \ ((env->c = getc(fin)) == '\n' ? \ (env->lineno++, env->c) : env->c) #define output(c) \ (putc(c, env->fout), ferror(env->fout) ? ioerr() : 0) output(input()) produces ((--(env->fout)->_cnt>=0? (int)(*(unsigned char*)(env->fout)->_ptr++=(((env->c=(--(fin)->_cnt>=0? (int)(*(unsigned char*)(fin)->_ptr++):_filbuf(fin)))=='\n'? (env->lineno++,env->c):env->c))): (((env->fout)->_flag&0200)&&-(env->fout)->_cnt<(env->fout)->_bufsiz? ((*(env->fout)->_ptr=(((env->c=(--(fin)->_cnt>=0? (int)(*(unsigned char*)(fin)->_ptr++):_filbuf(fin)))=='\n'? (env->lineno++,env->c):env->c)))!='\n'? (int)(*(unsigned char*)(env->fout)->_ptr++): _flsbuf(*(unsigned char*)(env->fout)->_ptr,env->fout)): _flsbuf((unsigned char)(((env->c=(--(fin)->_cnt>=0? (int)(*(unsigned char*)(fin)->_ptr++):_filbuf(fin)))=='\n'? (env->lineno++,env->c):env->c)),env->fout))), (((env->fout)->_flag&040)!=0)?ioerr():0) Ahh, lovely parentheses. :-) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!mimsy!chris ARPA/CSNet: chris@mimsy.umd.edu