Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. == vs =

== vs =

Scheduled Pinned Locked Moved The Lounge
c++visual-studiohelp
46 Posts 23 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Maximilien

    set your compiler warning to "level 4"


    Maximilien Lincourt Your Head A Splode - Strong Bad

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #5

    Maximilien wrote:

    set your compiler warning to "level 4"

    1. I never understood why they even give you different warning levels as an option 2) I've never understood why people don't use the highest warning level possible. 3) STL. Oh yeah. Marc Pensieve
    C J 2 Replies Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #6

      Try to get in the habit of putting constants and functions to the left of ==. Not only will it instantly flag such unintended assignments as errors at any warning level, but it often makes it easier to recognize them while scanning through code.

      ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

      R 1 Reply Last reply
      0
      • S Shog9 0

        Try to get in the habit of putting constants and functions to the left of ==. Not only will it instantly flag such unintended assignments as errors at any warning level, but it often makes it easier to recognize them while scanning through code.

        ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

        R Offline
        R Offline
        Ryan Binns
        wrote on last edited by
        #7

        Ugh. I hate that. I can see the minor potential benefits, but god it's awful and completely unnatural :~

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        J S 2 Replies Last reply
        0
        • R Ryan Binns

          Ugh. I hate that. I can see the minor potential benefits, but god it's awful and completely unnatural :~

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #8

          Is 1 == 2 more natural than 2 == 1?

          V 1 Reply Last reply
          0
          • R Ryan Binns

            Ugh. I hate that. I can see the minor potential benefits, but god it's awful and completely unnatural :~

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

            S Offline
            S Offline
            Shog9 0
            wrote on last edited by
            #9

            I don't really see much of a difference, so i use it. What is it that you find unnatural? (now on the other hand, i absolutely hate "safe" code that looks like this: if((((a/b)+c)==(d))||(((a*c)+b)==(z))) - i can understand not being entirely clear on operator precedence, but at some point you'd hope they'd stop typing and read up on it)

            ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

            J G J R 4 Replies Last reply
            0
            • S Shog9 0

              I don't really see much of a difference, so i use it. What is it that you find unnatural? (now on the other hand, i absolutely hate "safe" code that looks like this: if((((a/b)+c)==(d))||(((a*c)+b)==(z))) - i can understand not being entirely clear on operator precedence, but at some point you'd hope they'd stop typing and read up on it)

              ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #10

              Shog9 wrote:

              (((a/b)+c)==(d))||(((a*c)+b)==(z))

              People who write expressions like that only express one thing...

              S 1 Reply Last reply
              0
              • J Jorgen Sigvardsson

                Shog9 wrote:

                (((a/b)+c)==(d))||(((a*c)+b)==(z))

                People who write expressions like that only express one thing...

                S Offline
                S Offline
                Shog9 0
                wrote on last edited by
                #11

                I'm still hoping it's a secret pining for Lisp...

                ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                J 1 Reply Last reply
                0
                • S Shog9 0

                  I'm still hoping it's a secret pining for Lisp...

                  ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                  J Offline
                  J Offline
                  Jorgen Sigvardsson
                  wrote on last edited by
                  #12

                  At least you're forced to in Lisp... :)

                  1 Reply Last reply
                  0
                  • Richard Andrew x64R Richard Andrew x64

                    I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!

                    N Offline
                    N Offline
                    Nish Nishant
                    wrote on last edited by
                    #13

                    This would solve all your problems :-

                    class T
                    {
                    . . .
                    bool operator = (const T& t)
                    {
                    return operator ==(t);
                    }
                    . . .
                    }

                    :rolleyes: :rolleyes: :rolleyes: Regards, Nish


                    Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                    The Ultimate Grid - The #1 MFC grid out there!

                    Richard Andrew x64R 1 Reply Last reply
                    0
                    • N Nish Nishant

                      This would solve all your problems :-

                      class T
                      {
                      . . .
                      bool operator = (const T& t)
                      {
                      return operator ==(t);
                      }
                      . . .
                      }

                      :rolleyes: :rolleyes: :rolleyes: Regards, Nish


                      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                      The Ultimate Grid - The #1 MFC grid out there!

                      Richard Andrew x64R Offline
                      Richard Andrew x64R Offline
                      Richard Andrew x64
                      wrote on last edited by
                      #14

                      Well thanks everyone for your suggestions to turn up the warning level. The reason I didn't catch it before is because I'm using a class that someone else wrote that uses lots of old string functions. And when I build it, the output window gets filled with warnings about how this function is unsafe, and that function is unsafe, and this function will make your machine blow up, etc.! Thanks! Rich

                      S 1 Reply Last reply
                      0
                      • Richard Andrew x64R Richard Andrew x64

                        I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!

                        C Offline
                        C Offline
                        code frog 0
                        wrote on last edited by
                        #15

                        Troposphere wrote:

                        I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '=='

                        I love you! Apparently there are at least 2 mortals who come to this site on a regular basis. Stuff like that burns my butt when I catch myself at it.

                        I only read CP for the articles. Code-frog System Architects, Inc.

                        D L 2 Replies Last reply
                        0
                        • Richard Andrew x64R Richard Andrew x64

                          Well thanks everyone for your suggestions to turn up the warning level. The reason I didn't catch it before is because I'm using a class that someone else wrote that uses lots of old string functions. And when I build it, the output window gets filled with warnings about how this function is unsafe, and that function is unsafe, and this function will make your machine blow up, etc.! Thanks! Rich

                          S Offline
                          S Offline
                          Super Lloyd
                          wrote on last edited by
                          #16

                          Bloody typical with C++ if you ask me. One more reason to love C# if you ask me, relevant and concise error and warning message !

                          S J 2 Replies Last reply
                          0
                          • C code frog 0

                            Troposphere wrote:

                            I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '=='

                            I love you! Apparently there are at least 2 mortals who come to this site on a regular basis. Stuff like that burns my butt when I catch myself at it.

                            I only read CP for the articles. Code-frog System Architects, Inc.

                            D Offline
                            D Offline
                            DavidNohejl
                            wrote on last edited by
                            #17

                            code-frog wrote:

                            I love you! Apparently there are at least 2 mortals who come to this site on a regular basis.

                            LOL Never forget: "Stay kul and happy" (I.A.)
                            David's thoughts / dnhsoftware.org / MyHTMLTidy

                            1 Reply Last reply
                            0
                            • M Marc Clifton

                              That's nothing. Years ago, I spent half a day figuring out why this loop only exected one iteration:

                              for (int i=0; i<10; i++);
                              {
                              ... do something
                              }

                              BTW, isn't there a compiler warning for "are you sure you want to do an assignment here? Is your warning level set to the highest level? Marc Pensieve

                              G Offline
                              G Offline
                              Gary R Wheeler
                              wrote on last edited by
                              #18

                              Actually, doesn't that warning come out at level 3?


                              Software Zen: delete this;

                              Fold With Us![^]

                              1 Reply Last reply
                              0
                              • S Shog9 0

                                I don't really see much of a difference, so i use it. What is it that you find unnatural? (now on the other hand, i absolutely hate "safe" code that looks like this: if((((a/b)+c)==(d))||(((a*c)+b)==(z))) - i can understand not being entirely clear on operator precedence, but at some point you'd hope they'd stop typing and read up on it)

                                ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                                G Offline
                                G Offline
                                Gary R Wheeler
                                wrote on last edited by
                                #19

                                Well, at least I would write it as:

                                if((((a / b) + c) == d) ||
                                (((a * c) + b) == z))

                                I learned C back in the day when operator precedence enforcement was hit-or-miss in some compilers (yes, I'm that freakin' old). I was also programming in FORTRAN, Ada, and LISP at the time. It was just too bloody hard to remember the different rules for each language, so I learned to fully parenthesize. It could be worse. Here's an example of the coding style of one of my coworkers:

                                if (x == 2 || x == 6 && y > 5) for (int i = -1; i < 10; ++i)
                                InvokeMethod(i,x,y); else InvokeMethod2(x);

                                He avoids braces '{}' and parentheses whenever possible, and just strings everything together on one line like a sentence. He's also one of these object-oriented-out-the-wazoo types, who never puts more than four or five lines of code in a single function. His code is almost impossible to follow. The only saving grace is he does adhere to our naming conventions.


                                Software Zen: delete this;

                                Fold With Us![^]

                                J 1 Reply Last reply
                                0
                                • S Super Lloyd

                                  Bloody typical with C++ if you ask me. One more reason to love C# if you ask me, relevant and concise error and warning message !

                                  S Offline
                                  S Offline
                                  Shog9 0
                                  wrote on last edited by
                                  #20

                                  Just wait. C/C++ has had thirty years to collect warnings and errors, not to mention rules that makes it difficult for them to be specific and clear. C# will get there[^] too...

                                  ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                                  1 Reply Last reply
                                  0
                                  • S Shog9 0

                                    I don't really see much of a difference, so i use it. What is it that you find unnatural? (now on the other hand, i absolutely hate "safe" code that looks like this: if((((a/b)+c)==(d))||(((a*c)+b)==(z))) - i can understand not being entirely clear on operator precedence, but at some point you'd hope they'd stop typing and read up on it)

                                    ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                                    J Offline
                                    J Offline
                                    Judah Gabriel Himango
                                    wrote on last edited by
                                    #21

                                    Shog9 wrote:

                                    but at some point you'd hope they'd stop typing and read up on it)

                                    I always tell people, Please Excuse My Dear Aunt Sally (Parenthesis, Exponents, Multiplication, Division, Addition, Subtraction, in that order)

                                    Tech, life, family, faith: Give me a visit. I'm currently blogging about: Connor's Christmas Spectacular! Judah Himango

                                    C 1 Reply Last reply
                                    0
                                    • M Marc Clifton

                                      Maximilien wrote:

                                      set your compiler warning to "level 4"

                                      1. I never understood why they even give you different warning levels as an option 2) I've never understood why people don't use the highest warning level possible. 3) STL. Oh yeah. Marc Pensieve
                                      C Offline
                                      C Offline
                                      Chris Losinger
                                      wrote on last edited by
                                      #22

                                      Marc Clifton wrote:

                                      1. STL. Oh yeah.

                                      that's what i have a little header called WarnPragmas.h that is nothing but #pragmas which shut off all those annoying STL-related warnings. Cleek | Image Toolkits | Thumbnail maker

                                      1 Reply Last reply
                                      0
                                      • J Judah Gabriel Himango

                                        Shog9 wrote:

                                        but at some point you'd hope they'd stop typing and read up on it)

                                        I always tell people, Please Excuse My Dear Aunt Sally (Parenthesis, Exponents, Multiplication, Division, Addition, Subtraction, in that order)

                                        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Connor's Christmas Spectacular! Judah Himango

                                        C Offline
                                        C Offline
                                        Chris Losinger
                                        wrote on last edited by
                                        #23

                                        Judah Himango wrote:

                                        Please Excuse My Dear Aunt Sally

                                        of course i read that as "Please Execute My Dear Aunt Sally" Cleek | Image Toolkits | Thumbnail maker

                                        J 1 Reply Last reply
                                        0
                                        • C Chris Losinger

                                          Judah Himango wrote:

                                          Please Excuse My Dear Aunt Sally

                                          of course i read that as "Please Execute My Dear Aunt Sally" Cleek | Image Toolkits | Thumbnail maker

                                          J Offline
                                          J Offline
                                          Judah Gabriel Himango
                                          wrote on last edited by
                                          #24

                                          Got something against your Aunt? :)

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups