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. Other Discussions
  3. The Weird and The Wonderful
  4. A simple one...

A simple one...

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++
10 Posts 8 Posters 3 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.
  • A Offline
    A Offline
    Asad_KA
    wrote on last edited by
    #1

    Found in C++ code of one of my colleagues several years ago: if (x == 0) { y = 0; } else { y = x; } Asad

    P R S 3 Replies Last reply
    0
    • A Asad_KA

      Found in C++ code of one of my colleagues several years ago: if (x == 0) { y = 0; } else { y = x; } Asad

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      I would wonder whether or not it was originally something like:

      if (x == **FALSE**)
      {
          y = 0;
      } 
      else 
      {
          y = x;
      }
      

      (With FALSE being 0 of course.)

      J V 2 Replies Last reply
      0
      • P PIEBALDconsult

        I would wonder whether or not it was originally something like:

        if (x == **FALSE**)
        {
            y = 0;
        } 
        else 
        {
            y = x;
        }
        

        (With FALSE being 0 of course.)

        J Offline
        J Offline
        JeffPClark
        wrote on last edited by
        #3

        Something similar: if (x == false) { return false; } else { return true; }

        Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio

        J 1 Reply Last reply
        0
        • J JeffPClark

          Something similar: if (x == false) { return false; } else { return true; }

          Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          Your example is from someone not knowing (or being reluctant to use) boolean logic:

          return (x != false);

          would have been the same.


          Failure is not an option - it's built right in.

          J 1 Reply Last reply
          0
          • J jhwurmbach

            Your example is from someone not knowing (or being reluctant to use) boolean logic:

            return (x != false);

            would have been the same.


            Failure is not an option - it's built right in.

            J Offline
            J Offline
            JeffPClark
            wrote on last edited by
            #5

            Or just: return x;

            Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio

            J 1 Reply Last reply
            0
            • P PIEBALDconsult

              I would wonder whether or not it was originally something like:

              if (x == **FALSE**)
              {
                  y = 0;
              } 
              else 
              {
                  y = x;
              }
              

              (With FALSE being 0 of course.)

              V Offline
              V Offline
              Vasudevan Deepak Kumar
              wrote on last edited by
              #6

              PIEBALDconsult wrote:

              (With FALSE being 0 of course.)

              No longer. C# is getting stricter. You have to explicitly do a type cast to escape the compiler wrath and whip.

              Vasudevan Deepak Kumar Personal Homepage Tech Gossips

              1 Reply Last reply
              0
              • J JeffPClark

                Or just: return x;

                Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio

                J Offline
                J Offline
                jhwurmbach
                wrote on last edited by
                #7

                Sure. That would convert X's type (maybe BOOL?) implicitly to bool, whereas the operator!= I used does this explicitly. It probably doesn't matter.


                Failure is not an option - it's built right in.

                1 Reply Last reply
                0
                • A Asad_KA

                  Found in C++ code of one of my colleagues several years ago: if (x == 0) { y = 0; } else { y = x; } Asad

                  R Offline
                  R Offline
                  Rage
                  wrote on last edited by
                  #8

                  Does it make more sense if x is of type signed int and y of type unsigned int ?

                  http://www.readytogiveup.com/[^] - Do something special today.

                  G 1 Reply Last reply
                  0
                  • A Asad_KA

                    Found in C++ code of one of my colleagues several years ago: if (x == 0) { y = 0; } else { y = x; } Asad

                    S Offline
                    S Offline
                    Sylvester george
                    wrote on last edited by
                    #9

                    Good :) Great :laugh: High level of thinking :laugh::laugh::laugh:

                    Regards, Sylvester G

                    1 Reply Last reply
                    0
                    • R Rage

                      Does it make more sense if x is of type signed int and y of type unsigned int ?

                      http://www.readytogiveup.com/[^] - Do something special today.

                      G Offline
                      G Offline
                      Guffa
                      wrote on last edited by
                      #10

                      No...

                      --- single minded; short sighted; long gone;

                      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