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. Once more unto the C++, dear friends, once more

Once more unto the C++, dear friends, once more

Scheduled Pinned Locked Moved The Lounge
questionc++csscom
35 Posts 18 Posters 0 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.
  • P Peter Mulholland

    what about swapping 2 values without a temp variable:

    char\* start = str;
    char\* end = str + (strlen(str) - 1);
    
    while (start < end) 
    {
        \*start ^= \*end;
        \*end ^= \*start;
        \*start++ ^= \*end--;
    }
    return str;
    

    Pete

    J Offline
    J Offline
    John M Drescher
    wrote on last edited by
    #22

    I remember that you can do this with XORs however for code readability I would never do that in a program.

    John

    N 1 Reply Last reply
    0
    • J John M Drescher

      I remember that you can do this with XORs however for code readability I would never do that in a program.

      John

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #23

      John M. Drescher wrote:

      you can do this with XORs however for code readability I would never do that in a program

      Meh, pack it into a well named inline function, such as swap_in_place() and the readability problem is solved.

      utf8-cpp

      J 1 Reply Last reply
      0
      • R RugbyLeague

        I am converting a compiler and language runtime written in C++ into C# - that's fun :^)

        J Offline
        J Offline
        John M Drescher
        wrote on last edited by
        #24

        I have lots of fun doing the reverse. :laugh:

        John

        1 Reply Last reply
        0
        • J John M Drescher

          Dan Neely wrote:

          It's retarded.

          Agreed. Although, in the 600K to 800K lines of C++ I have produced I do not recall ever using that one time. I would have had to look it up if I saw it..

          John

          S Offline
          S Offline
          Single Step Debugger
          wrote on last edited by
          #25

          I’m not agreed. It was all over my code for almost three years. XOR is very heavily used in the cryptography.

          The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

          J 1 Reply Last reply
          0
          • S Single Step Debugger

            I’m not agreed. It was all over my code for almost three years. XOR is very heavily used in the cryptography.

            The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

            J Offline
            J Offline
            John M Drescher
            wrote on last edited by
            #26

            Deyan Georgiev wrote:

            XOR is very heavily used in the cryptography.

            You just reminded me.. I actually may have to dig into this soon to interface with a medical workstation. I will probably just use a standard library however.

            John

            1 Reply Last reply
            0
            • P pelnor

              I have not written any C++ code since 2001. Now I'm dragging one of my old dll's out of mothballs to add some new features. Some where in those 8 absent years the garbage collector or my brain declared C++ syntax of no use and deleted it for me. Now I'm staring at my code wondering what all the hieroglyphics are for. Let's see there's this * guy. He's got something to do with pointers. It's attached or next to some of my variables. Then there's ::, <<, >>, wait.... wait, it's coming back to me.... "<<" is super less than. Got it moving on. Then I run into ^. Oh come on! Who thought ^ was a good idea? Linker? what is that? You mean I have to tell this linker of yours where to look for things just so I can compile? There isn't just a magic "make it go button"? This is going to be a long day. Better load up on the caffeine.

              Latest toy built for fun: Web Lens Best feature: Full size images when using Google image search.

              J Offline
              J Offline
              Joe Woodbury
              wrote on last edited by
              #27

              pelnor wrote:

              Then I run into ^. Oh come on! Who thought ^ was a good idea?

              That's in C# too. And I've used it. (If you're going to harp on symbols, how about & meaning concatenate in VB? Or the difference between \ and /? Of course, just like in C++ and C#, once you know them, you know them.)

              T 1 Reply Last reply
              0
              • R RugbyLeague

                I am converting a compiler and language runtime written in C++ into C# - that's fun :^)

                J Offline
                J Offline
                Joe Woodbury
                wrote on last edited by
                #28

                A few weeks ago I moved a chunk of code from C++ to C#. It required very few minor changes, which was so disconcerting that I kept figuring I did something wrong. But it compiled and worked!

                1 Reply Last reply
                0
                • P pelnor

                  Several years of VB got in the way. I mostly do c# now so it's not tooooo much culture shock. Just some head scratching.

                  Latest toy built for fun: Web Lens Best feature: Full size images when using Google image search.

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

                  pelnor wrote:

                  Several years of VB got in the way

                  You're lucky all you forgot was C++...

                  1 Reply Last reply
                  0
                  • J Joe Woodbury

                    pelnor wrote:

                    Then I run into ^. Oh come on! Who thought ^ was a good idea?

                    That's in C# too. And I've used it. (If you're going to harp on symbols, how about & meaning concatenate in VB? Or the difference between \ and /? Of course, just like in C++ and C#, once you know them, you know them.)

                    T Offline
                    T Offline
                    thrakazog
                    wrote on last edited by
                    #30

                    Joe Woodbury wrote:

                    That's in C# too. And I've used it.

                    The symbol being there is one thing. How it works and what it represents is another. My favorite was always the := in ADA. Wasn't = good enough for them? Some languages can be similar and still miles apart. Or as Homer would say: Le grille? What the hell is that?[^]

                    D N 2 Replies Last reply
                    0
                    • T thrakazog

                      Joe Woodbury wrote:

                      That's in C# too. And I've used it.

                      The symbol being there is one thing. How it works and what it represents is another. My favorite was always the := in ADA. Wasn't = good enough for them? Some languages can be similar and still miles apart. Or as Homer would say: Le grille? What the hell is that?[^]

                      D Offline
                      D Offline
                      Dan Neely
                      wrote on last edited by
                      #31

                      1970 - Niklaus Wirth creates Pascal, a procedural language. Critics immediately denounce Pascal because it uses "x := x + y" syntax instead of the more familiar C-like "x = x + y". This criticism happens in spite of the fact that C has not yet been invented. :-\ http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html[^]

                      The latest nation. Procrastination.

                      1 Reply Last reply
                      0
                      • T thrakazog

                        Joe Woodbury wrote:

                        That's in C# too. And I've used it.

                        The symbol being there is one thing. How it works and what it represents is another. My favorite was always the := in ADA. Wasn't = good enough for them? Some languages can be similar and still miles apart. Or as Homer would say: Le grille? What the hell is that?[^]

                        N Offline
                        N Offline
                        Nemanja Trifunovic
                        wrote on last edited by
                        #32

                        thrakazog wrote:

                        My favorite was always the := in ADA. Wasn't = good enough for them?

                        My favorite was always the == in C. Wasn't = good enough for them?

                        utf8-cpp

                        J 1 Reply Last reply
                        0
                        • P pelnor

                          Several years of VB got in the way. I mostly do c# now so it's not tooooo much culture shock. Just some head scratching.

                          Latest toy built for fun: Web Lens Best feature: Full size images when using Google image search.

                          A Offline
                          A Offline
                          AspDotNetDev
                          wrote on last edited by
                          #33

                          Same here. It took me a good while to figure out how to include files properly (i.e., how .h and .cpp relate).

                          Visual Studio is an excellent GUIIDE.

                          1 Reply Last reply
                          0
                          • N Nemanja Trifunovic

                            John M. Drescher wrote:

                            you can do this with XORs however for code readability I would never do that in a program

                            Meh, pack it into a well named inline function, such as swap_in_place() and the readability problem is solved.

                            utf8-cpp

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

                            Along with a small comment, describing the "trick". Nobody will ever have a hard time understanding that. If they would, they probably shouldn't be programmers anyway...

                            1 Reply Last reply
                            0
                            • N Nemanja Trifunovic

                              thrakazog wrote:

                              My favorite was always the := in ADA. Wasn't = good enough for them?

                              My favorite was always the == in C. Wasn't = good enough for them?

                              utf8-cpp

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

                              :laugh: I almost replied with a dry explanation. Then it hit me. Your sarcasm. :-D

                              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