Path: utzoo!utgpu!water!watmath!clyde!rutgers!sunybcs!boulder!hao!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: a couple quickies Message-ID: <10066@mimsy.UUCP> Date: 7 Jan 88 00:21:09 GMT References: <11140@brl-adm.ARPA> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 106 In article <11140@brl-adm.ARPA> TLIMONCE%DREW.BITNET@CUNYVM.CUNY.EDU writes: >My understanding is that the drafts and the actual standard are released >into the public domain. Correct? No. The drafts and the standard are copyright by ANS. >If so, would their be any problems with someone sending copies of >the next draft electronically? Yes. Also, due to reasons that apparently boil down to `we never did it that way before and it would be hard to start now' [*], you cannot buy it in electronic form. [*`We' is not X3J11. There is some sort of political split between the groups that do the standards and the group(s) that publish the standard, such that neither has much influence on the other. This is all second (or worse) hand information.] >(new topic) >"Is ANSI C good for systems programming?" someone asked. I think so. In >fact, with prototypes, one should expect more reliable programs. I think prototypes are a Good Thing. I am not at all certain that they should be in the (first?) C standard. (Indeed, I happen to believe that when prototypes are added, default declarations should be removed entirely. Combining the two just makes the language awkward.) >(new topic) >Question: Under ANSI C, > for (i = 0; i == 100; i++) foo(&i); >If foo() does something like: "*i = 0" will this loop ever complete? The loop will not run at all unless you use a different test. I assume you mean something like for (i = 0; i < 100; i++) foo(&i); If foo is `foo (int *ip) { *ip = 0; }', the loop does not terminate. How `noalias' affects this I do not know. >I hope this is classified as undefined. I hope not! The for loop `for (init; test; iterate) body;' is defined as being approximately equivalent to init; while (test) { body; iterate; } If the compiler discovers that `foo' neither reads nor alters i, it could then rewrite the loop as = 100; while (-- >= 0) foo(&i); i = 100; If the loop does read i but does not alter it, the compiler may use = 100, i = 0; while (-- >= 0) { foo(&i); i++; } Unless there is a great deal of code inside the loop that uses i, or comparison against zero rather than a constant (or register, if there is a spare register that can hold 100, or any other weird permutation), none of these changes is likely to make much difference. In the case where it does make such a difference, yet foo alters i, the compiler can do this: i = 0; while (i < 100) { foo(&i); = i; in place of i>; i = ; } or perhaps this: = 0; while ( < 100) { >; i = ; foo(&i); = i; >; } i = ; /* if needed */ Which (if any) of these is most efficient is very machine dependent. Doing a perfect job of discovering whether `foo' reads and/or alters `i' is difficult (equivalent to solving the halting problem). Doing a suitably good job is easy (opinion). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris