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. A 'head scratcher' problem

A 'head scratcher' problem

Scheduled Pinned Locked Moved The Lounge
c++helpquestion
20 Posts 9 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.
  • L Lost User

    Quote:

    The syntax is commonly used in for loops where you want to, say, increment two variables typically two indexes, or stepping two linked lists) before the next iteration.

    For me the syntax is used to make the code unreadable :)

    It does not solve my Problem, but it answers my question

    H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #11

    LOL, i'm guilty of using it in for loops sometimes.

    Real programmers use butterflies

    L 1 Reply Last reply
    0
    • H honey the codewitch

      LOL, i'm guilty of using it in for loops sometimes.

      Real programmers use butterflies

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #12

      You'll be burned anyway, so what's the point? ;P And yes of course, I do not know / use the syntax and therefore most probably my negative attitude for it ...

      It does not solve my Problem, but it answers my question

      H 1 Reply Last reply
      0
      • R Rick York

        Ah, write-only code. That makes me think of Forth.

        "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

        D Offline
        D Offline
        Daniel Pfeffer
        wrote on last edited by
        #13

        It brings APL to mind. AFAIK, the first write-only language by design.

        Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

        R B K 3 Replies Last reply
        0
        • S steveb

          I just found a bug that is beyond strange (unless I am missing something obvious) :

          float CStat::GetTotal() const
          {
          return m_fValue1 + m_fValue2 + m_fValue3 + m_fValue4, + m_fValue5;
          }

          Note the ',' comma before the

          , + m_fValue5;

          Visual C++ 2015 compiles this without errors. The return value is always 0 because m_fValue5 100% is zero but m_fValue1 through m_fValue3 are populated. This function returns 0 always. Does this returns m_fValue5 always? Apparently the syntax is legal

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

          Possibly why C# has altered the behavior of comma. (Sadly.)

          1 Reply Last reply
          0
          • D Daniel Pfeffer

            It brings APL to mind. AFAIK, the first write-only language by design.

            Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

            R Offline
            R Offline
            Rick York
            wrote on last edited by
            #15

            Yes, that's a good example. Thankfully I have never had the misfortune of using it.

            "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

            1 Reply Last reply
            0
            • D Daniel Pfeffer

              It brings APL to mind. AFAIK, the first write-only language by design.

              Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

              B Offline
              B Offline
              Brisingr Aerowing
              wrote on last edited by
              #16

              One of my friends from high school taught himself to read it. He could also read brainf***. Useless talents, but talents nonetheless. It was quite impressive.

              What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

              1 Reply Last reply
              0
              • L Lost User

                You'll be burned anyway, so what's the point? ;P And yes of course, I do not know / use the syntax and therefore most probably my negative attitude for it ...

                It does not solve my Problem, but it answers my question

                H Offline
                H Offline
                honey the codewitch
                wrote on last edited by
                #17

                It lets you declare multiple variables of the same type in a single statement.

                int i=0,ic=10;

                It's useful primarily for for() loops when you need multiple variable inits

                Real programmers use butterflies

                1 Reply Last reply
                0
                • S steveb

                  Doh! Never mind. Totally legal even though does not make any sense

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #18

                  Actually it makes a lot of sense. I use the comma operator in quite a few places.

                  1 Reply Last reply
                  0
                  • S steveb

                    I just found a bug that is beyond strange (unless I am missing something obvious) :

                    float CStat::GetTotal() const
                    {
                    return m_fValue1 + m_fValue2 + m_fValue3 + m_fValue4, + m_fValue5;
                    }

                    Note the ',' comma before the

                    , + m_fValue5;

                    Visual C++ 2015 compiles this without errors. The return value is always 0 because m_fValue5 100% is zero but m_fValue1 through m_fValue3 are populated. This function returns 0 always. Does this returns m_fValue5 always? Apparently the syntax is legal

                    C Offline
                    C Offline
                    Chris Maunder
                    wrote on last edited by
                    #19

                    The good ol' comma operator. Designed specifically to trap young players. I grew up, many moons ago, in the era of 80 x 25 character screens for programming and so squeezing as much code as you could into as few lines as possible saved the ESCCtrl + F / B keys from wearing out. The ++/-- operators, dense conditionals in loops and single character variable names were what kept you productive (sorta). Those days are long, long gone now. The comma operator now just gives me 'Nam flashbacks

                    cheers Chris Maunder

                    1 Reply Last reply
                    0
                    • D Daniel Pfeffer

                      It brings APL to mind. AFAIK, the first write-only language by design.

                      Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                      K Offline
                      K Offline
                      kalberts
                      wrote on last edited by
                      #20

                      Daniel Pfeffer wrote:

                      It brings APL to mind. AFAIK, the first write-only language by design.

                      Actually, it was developed for blackboard use. Kenneth Iverson was teaching matrix math at Harvard, as an extension of the classical math operators, as a notation for math expressions involving matrices. He was using it as a lecturing tool for several years, until someone at IBM suggested that just like a computer program could process plus and minus, it could handle matrix inversion and stuff like that - all those special symbols Iverson had been using on the letcuring hall blackboards. APL is like user friendly Unix: Unix is user friendly - it is just somewhat picky in who its friends are.

                      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