Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!spool.mu.edu!snorkelwacker.mit.edu!stanford.edu!agate!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: using "=" in a conditional (was Funny Mistake) Message-ID: <11195@dog.ee.lbl.gov> Date: 20 Mar 91 20:27:37 GMT References: <1991Mar20.031419.3677@isis.cs.du.edu> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 18 X-Local-Date: Wed, 20 Mar 91 12:27:37 PST In article <1991Mar20.031419.3677@isis.cs.du.edu> cla@isis.UUCP (Chuck Anderson) writes: >You can do a nice string copy with this construct as well: > while (*dest++ = *source++); Of course, you can also write it as: while ((*dest++ = *source++) != 0) /* or != '\0' */ /* void */; which will leave no doubt in the reader's mind that you meant `test the result of copying one element', and not `test one pair of elements'. Commenting the empty statement (here, with `void', though `do nothing' or `continue' or `skip' or ... are all fine) will also remove all doubt as to whether it, too, was unintended. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov