Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!mcsun!ukc!mucs!m1!bevan From: bevan@cs.man.ac.uk (Stephen J Bevan) Newsgroups: comp.lang.c Subject: Using `=' in a conditional (was Re: Funny mistake) Message-ID: Date: 17 Mar 91 19:26:22 GMT References: <1991Mar13.125034.2825@st-andy.uucp> <13337@helios.TAMU.EDU> <8148@rsiatl.Dixie.Com> <15481@smoke.brl.mil> <775@camco.Celestial.COM> Sender: news@cs.man.ac.uk Distribution: comp Organization: Department of Computer Science, University of Manchester Lines: 32 In-reply-to: bill@camco.Celestial.COM's message of 16 Mar 91 21:54:32 GMT In <775@camco.Celestial.COM> bill@camco.Celestial.COM (Bill Campbell) writes : ]In <15481@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: ] ]>In article <8148@rsiatl.Dixie.Com> stan@Dixie.Com (Stan Brown) writes: ]>>>"if (a = b)" instead of "if (a == b)". ]>>... I have yet to see a UNIX compiler complain about it ] ]>That's good, because it is valid C and the compiler cannot know whether ]>or not it reflects the programmer's intentions. ] ]My personal preferance would be a WARNING message. Certainly it ]is a legal construction, but 90% of the time when I do this it ]was my mistake! This warning had better be optional. Also if you really want a warning, I'd like it to be a bit more selective than just warning about an assignment, I'd like to warn depending on what was being assigned. For example I view the following as quite different cases :- if (a= b) ... if (a= some_fun()) ... I've never actually done the former, but I use the latter regularly. Note the way the assignment is written. I remember reading about `=' vs `==' before I started using C and decided to follow some advice to write assigment assymetrically i.e. `a= b' rather than `a = b'. For what its worth, I haven't been programming in C that long (3 - 4 years), but I can't actually remember using a `=' when I meant `=='. I've made plenty of other mistakes though :-) bevan