From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,751584f55705ddb7 X-Google-Attributes: gid103376,public From: ncohen@watson.ibm.com (Norman H. Cohen) Subject: Re: Side-effect arithmetic again [was: Ada ... in embedded systems] Date: 1996/03/25 Message-ID: <4j6d12$lbn@watnews1.watson.ibm.com>#1/1 X-Deja-AN: 144177044 distribution: world references: organization: IBM T.J. Watson Research Center reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada Date: 1996-03-25T00:00:00+00:00 List-Id: In article , stt@henning.camb.inmet.com (Tucker Taft) writes: |> As a small anecdote here relating to the "op=" operations of C, |> my most recent "favorite" bug in C code I was writing was in the following: |> |> if (a /= b) { |> ... |> } |> |> The GCC compiler nicely warns you if you write "if (a = b) {" and |> suggests an extra level of parentheses to emphasize that you really |> want an assignment, not an equality, operator. Unfortunately, it |> isn't so helpful with the "op=" operators, and presumes that if |> you use one of those, you know what you are doing. Alas, after |> writing a lot of Ada, I didn't in this case. Of course what I meant |> was "if (a != b) {". Instead, I divided A by B, and tested the result |> for non-zero-ness. Groink! Yes, I've done the same thing. It's one of a group of C pitfalls to which Ada programmers are especially susceptible. Another is to leave the empty parentheses off a parameterless function call in a context in which C is willing to accept a pointer-valued expression. There are far too many such contexts. When I wrote if ( some_predicate ) { ... } instead of if ( some_predicate() ) { ... } C obediently coerced some_predicate to a pointer to the function and tested whether that pointer was null. As Tuck so eloquently put it, Groink! |> At this point Dave Emery comes on and asks me why in the world |> I am writing any code in C... ;-} So we don't start to take Ada for granted, of course. ;-) -- Norman H. Cohen ncohen@watson.ibm.com