Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!pt.cs.cmu.edu!k.gp.cs.cmu.edu!dandb From: dandb@k.gp.cs.cmu.edu (Dean Rubine) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr), where cptr is a *) Keywords: really about using the comma operator Message-ID: <5630@pt.cs.cmu.edu> Date: 25 Jul 89 06:11:17 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> <10100@mpx2.mpx.com> <10562@smoke.BRL.MIL> <1989Jul24.194646.3012@nc386.uucp> Organization: Carnegie-Mellon University, CS/RI Lines: 33 A slightly better use of a comma in a while expression is: while(printf("? "), gets(line) != NULL) { ... whatever ... } I think it beats the alternatives: for(;;) { printf("? "); if(gets(line) == NULL) break; ... whatever ... } -- or -- for(printf("? "); gets(line) != NULL; printf("? ")) { ... whatever ... } I also occasionally use the comma to save braces: if((f = fopen(file, "r")) == NULL) fprintf(stderr, "Can't open %s\n", file), exit(2); -- ARPA: Dean.Rubine@CS.CMU.EDU UUCP: ...!seismo!k.gp.cs.cmu.edu!dandb PHONE: 412-268-2613 [ Free if you call from work] US MAIL: Computer Science Dept / Carnegie Mellon U / Pittsburgh PA 15213 DISCLAIMER: My employer wishes I would stop posting and do some work.