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. The holy comma operator [modified]

The holy comma operator [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++pythonlearning
14 Posts 13 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.
  • D Doc Lobster

    happened to me today: (in C++)

    if (condA ||
    condB ||
    condC ||
    condD,
    condE)
    {
    ...
    }

    Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g. int x=3, y=5; until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007

    T Offline
    T Offline
    Tony Wesley
    wrote on last edited by
    #4

    Unless there are side effects of the other conditions, your example is the equaivant of this:

    if (condE)
    {
    ...
    }

    D 1 Reply Last reply
    0
    • T Tony Wesley

      Unless there are side effects of the other conditions, your example is the equaivant of this:

      if (condE)
      {
      ...
      }

      D Offline
      D Offline
      Doc Lobster
      wrote on last edited by
      #5

      Right. One can probably do awful things using commas given the right modulation of commas and semicolons - even outside variable declarations and for-statements.

      N A 2 Replies Last reply
      0
      • D Doc Lobster

        Right. One can probably do awful things using commas given the right modulation of commas and semicolons - even outside variable declarations and for-statements.

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

        Doc Lobster wrote:

        One can probably do awful things using commas

        ... such as implementing an assignment library[^] :)


        Programming Blog utf8-cpp

        C M 2 Replies Last reply
        0
        • N Nemanja Trifunovic

          Doc Lobster wrote:

          One can probably do awful things using commas

          ... such as implementing an assignment library[^] :)


          Programming Blog utf8-cpp

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

          or obfuscation!

          image processing toolkits | batch image processing

          1 Reply Last reply
          0
          • D Doc Lobster

            Right. One can probably do awful things using commas given the right modulation of commas and semicolons - even outside variable declarations and for-statements.

            A Offline
            A Offline
            Anthony Mushrow
            wrote on last edited by
            #8

            So, next time you quit a job because you hate it, don't forget to throw in a few commas here and there ;)

            My current favourite word is: PIE! I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for. -The Undefeated

            M 1 Reply Last reply
            0
            • A Anthony Mushrow

              So, next time you quit a job because you hate it, don't forget to throw in a few commas here and there ;)

              My current favourite word is: PIE! I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for. -The Undefeated

              M Offline
              M Offline
              Michael Davey 1
              wrote on last edited by
              #9

              hehe.. I like your style :)

              Michael Davey biproject.com rss and blog news in a more palatable format mobile edition now available!

              1 Reply Last reply
              0
              • N Nemanja Trifunovic

                Doc Lobster wrote:

                One can probably do awful things using commas

                ... such as implementing an assignment library[^] :)


                Programming Blog utf8-cpp

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #10

                I :love: how the docs page starts with that quote from Stroustrup.

                --Mike-- Visual C++ MVP :cool: LINKS~! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ "That's what's great about doing user interface work. No matter what you do, people will say that what you did was idiotic." -- Raymond Chen

                1 Reply Last reply
                0
                • S Steve Hansen

                  So what's the result? In C# it just says that the comma is invalid there.

                  K Offline
                  K Offline
                  Kastellanos Nikos
                  wrote on last edited by
                  #11

                  Steve Hansen wrote:

                  In C# it just says that the comma is invalid there.

                  yah :sigh:

                  1 Reply Last reply
                  0
                  • D Doc Lobster

                    happened to me today: (in C++)

                    if (condA ||
                    condB ||
                    condC ||
                    condD,
                    condE)
                    {
                    ...
                    }

                    Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g. int x=3, y=5; until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007

                    M Offline
                    M Offline
                    Mehmet Suyuti Dindar
                    wrote on last edited by
                    #12

                    Comma operator generates right operand value so condE for this example.

                    1 Reply Last reply
                    0
                    • D Doc Lobster

                      happened to me today: (in C++)

                      if (condA ||
                      condB ||
                      condC ||
                      condD,
                      condE)
                      {
                      ...
                      }

                      Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g. int x=3, y=5; until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007

                      F Offline
                      F Offline
                      f2
                      wrote on last edited by
                      #13

                      easiest mistake is not comma is == sign by just =

                      from, -= aLbert =-

                      1 Reply Last reply
                      0
                      • D Doc Lobster

                        happened to me today: (in C++)

                        if (condA ||
                        condB ||
                        condC ||
                        condD,
                        condE)
                        {
                        ...
                        }

                        Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g. int x=3, y=5; until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007

                        J Offline
                        J Offline
                        jschell
                        wrote on last edited by
                        #14

                        Of course in C++ the comma operator can be overloaded like most others. So one can make things really interesting.

                        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