Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!linus!philabs!cmcl2!seismo!brl-tgr!tgr!cottrell@NBS-VMS.ARPA From: cottrell@NBS-VMS.ARPA (COTTRELL, JAMES) Newsgroups: net.lang.c Subject: C Bites Message-ID: <1963@brl-tgr.ARPA> Date: Mon, 7-Oct-85 19:19:29 EDT Article-I.D.: brl-tgr.1963 Posted: Mon Oct 7 19:19:29 1985 Date-Received: Wed, 9-Oct-85 06:31:42 EDT Sender: news@brl-tgr.ARPA Lines: 76 /* > The reason I don't like: > > if(condition) { > s1; > s2; > } > can be shown by the following source: > > if (onelock(pid, tempfile, file) == -1) { > /* lock file exists */ > /* get status to check age of the lock file */ > ret = stat(file, &stbuf); > if (ret != -1) { > time(&ptime); > if ((ptime - stbuf.st_ctime) < atime) { > /* file not old enough to delete */ > return(FAIL); > } > ------------------------------------------------------------------------------ > } > ret = unlink(file); > ret = onelock(pid, tempfile, file); > if (ret != 0) > return(FAIL); > } > stlock(file); > > When I listed the file out, the page break was right where the dashed line is. Sorry, no dice. First off, the page break comes there regardless of how the `if' lines are formatted. Second off, what is the page break doing there anyway? Don't you know about Form Feeds? Funxions on one page please. > > Why do you like this style? This seems to indicate that > >the braces are associated in your mind with the enclosed statements. > > You seem to have answered your own question. What else are the braces related > to if not the enclosed statements? Note the following, which has nothing to do > with if's, while's, for's, or do's. > > main() > { > int i = 42; > float foo = 3.14159; > > printf("Starting program\n"); > printf("i = %d, foo = %f\n",i,foo); > > { /* Truly local variables */ > static char *foo = "What is the meaning of life?"; > double i = 1.414; > > printf("Another message\n"); > printf("i = %f, foo = %s\n",i,foo); > } > /* Back to the old variables */ > > printf("Yet another message\n"); > printf("i = %d, foo = %f\n",i,foo); > exit(0); > } How many people axually do this? I mean use nested blox? Most people use braces only where necessary. I have seen the trick #define save(x) { int save; save = x; #define restore(x) x = save; } which make use of this technique, but I feel nested variables (which usurp the scope of more global variables) are a relatively bad practice. If it's big enuf for it's own scope, it probably should be a funxion. jim cottrell@nbs */ ------