Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!oliveb!ames!fxgrp!ljz From: ljz@fxgrp.UUCP (Lloyd Zusman, Master Byte Software) Newsgroups: comp.lang.c Subject: Re: (So-Called) ANSI C Message-ID: <194@fxgrp.UUCP> Date: 8 Jan 88 22:46:29 GMT References: <4668@pyr.gatech.EDU> <495@xyzzy.UUCP> <9930@mimsy.UUCP> <6996@brl-smoke.ARPA> <10027@ut-sally.UUCP> Reply-To: fxgrp!ljz@ames.arpa (Lloyd Zusman, Master Byte Software) Followup-To: <10027@ut-sally.UUCP> nather@ut-sally.UUCP (Ed Nather) Organization: FX Development Group, Inc., Mountain View, CA Lines: 48 In article <10027@ut-sally.UUCP> nather@ut-sally.UUCP (Ed Nather) writes: > ... > [ regarding the == and = opertors in an 'if' statement ] > ... >It isn't a typo. I use it all the time to assign a value to a variable, >then test the result. I find it seriously irritating that Turbo C >crabs about the construction. Like everyone else, I have written "=" >when I meant "==" ... just as I have made many bonehead errors in >writing code. But I don't blame the compiler, or the langauge, when >I do. > ... With regard to == and = in 'if' statements, here's a handy trick taught to me by an associate that some of you might find useful if you don't have a C compiler such as Turbo C that complains about = in 'if' statements: When you are comparing a variable to a constant, you probably normally do it like this: if (var == CONST) ... This can cause difficult-to-find problems if you screw up and write it like this: if (var = CONST) ... But if instead, you write it like if (CONST == var) ... you won't have the same problem, since the construct if (CONST = var) ... will always generate an error. Thanks to Robert Johnsen of Saratoga, California, for teaching me this handy trick. Sorry if this has already appeared on the net recently. ------------------------------------------------------------------------- Lloyd Zusman Master Byte Software Los Gatos, California Internet: fxgrp!ljz@ames.arpa "We take things well in hand." UUCP: ...!ames!fxgrp!ljz