Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: My C program does not compile or gives segmentation fault Date: Mon, 27 Mar 2017 08:49:01 -0700 Organization: None to speak of Lines: 75 Message-ID: References: <89549322-236e-4a59-9bb5-dc881593a846@googlegroups.com> <1b709495-03da-462d-926f-3ee2be0a7ab5@googlegroups.com> <58d642e0.2297265@news.xs4all.nl> <58d6e0b3.20124312@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="bc4ad8e6098eee52cc8cf8ccb2486caf"; logging-data="2925"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qPtYxzEjmMPuwlYYnlthK" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:qU0cq9cuoIUqK03rZXFWPouiGo4= sha1:4Ujy8qUS8p9pq0rlCWzOvWw0OII= Xref: csiph.com comp.lang.c:107164 Richard Heathfield writes: > On 26/03/17 10:39, Keith Thompson wrote: >> Richard Heathfield writes: >> [...] >>> Anyone who is bright enough to understand that addition is commutative >>> (and thus that x + y gives the same result as y + x) is also bright >>> enough to understand that comparison for equality is commutative (and >>> thus that x == y gives the same results as y == x). >>> >>> Anyone who is not bright enough to understand commutativity needs to be >>> looking at other careers. >>> >>> Everybody in this thread who has expressed an opinion /is/ bright enough >>> to understand commutativity, so I really, truly don't see why they are >>> so upset by 3 == x. Do these same people find it difficult to read B == x? >> >> I see that you don't understand. > > I think I'm beginning to. > >> Repeating that addition and equality are commutative is not helpful. >> We all know that. > > I know you all know that. Because I know you all know that, I'm really > struggling to see why you have an issue here. > >> I assure you that (a) I understand perfectly well that `x == 3` and >> `3 == x` are equivalent, and (b) I find `3 == x` ugly and jarring. > > I accept your assurance. I find it strange, but I accept it. Thank you. >> Can we start by acknowledging that I'm not just making that up, >> and that a lot of people share the same feeling? > > Yes, but let's be clear that it's a /feeling/. It doesn't seem to have > any logical grounds whatsoever. That was just a starting point. I assert that there *are* some (fuzzy) logical grounds (and some people in this thread have tried to explain them). ("Fuzzy logic" is a thing, but it's not what I'm referring to.) Nobody looks at C expressions purely in terms of their C semantics. We consider context, both within and outside the program. Certainly `x == 3` is an expression, specifically an equality-expression. But I also think of it as a statement *about x*. x has some value. Is that value (equal to) 3? Yes it is, or no it isn't. Evaluating the comparison tells me something about x. By contrast, `3 == x` seems like a statement *about 3*. 3 has some value. Is that value equal to the value of x? Yes it is, or no it isn't. By evaluating that expression, I haven't learned anything new about 3. And if C had chosen assignment and equality operators that aren't so easy to mix up (say, := for assignment and == for equality), I don't think anybody would ever consider writing `if (3 == x)`. There are other cases where order matters for clarity even if it doesn't matter semantically. If I want to compute the distance from the origin of the point (x, y), I'll write sqrt(x*x + y*y) Writing sqrt(y*y + x*x) would be weird. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"