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. General Programming
  3. C / C++ / MFC
  4. comma operator

comma operator

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
6 Posts 4 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.
  • M Offline
    M Offline
    Marissa182
    wrote on last edited by
    #1

    how come the comma operator isnt used more often i was able to write a whole function using 1 semi color at the end so how come people dont use the commas? is there a performance reason or somethting?

    D M R 3 Replies Last reply
    0
    • M Marissa182

      how come the comma operator isnt used more often i was able to write a whole function using 1 semi color at the end so how come people dont use the commas? is there a performance reason or somethting?

      D Offline
      D Offline
      Dave Bryant
      wrote on last edited by
      #2

      Mainly because it makes it a lot harder to see what is going if the comma operator is used for anything more complicated than a fairly trivial statement. If you write a complex function in one line using the comma operator, and then come back to it 6 months or a year later, it would be considerably more difficult to understand what is going on, than if it were written clearly in multiple statements. It is mainly useful in contexts where only a single statement is allowed - for example, in the increment statement of a for loop. for ( int i = 0, j = 10 ; i < nCount ; ++i, --j ) {   // ... } Dave http://www.cloudsofheaven.org

      1 Reply Last reply
      0
      • M Marissa182

        how come the comma operator isnt used more often i was able to write a whole function using 1 semi color at the end so how come people dont use the commas? is there a performance reason or somethting?

        M Offline
        M Offline
        Maxwell Chen
        wrote on last edited by
        #3

        :confused: :confused: :confused: Comma is used heavily in our code... while you declaring functions. For example:

        void Foo(int iNumber, bool bFlag);
        BOOL Move(HWND hWnd, LONG x, LONG y, ULONG cx, ULONG cy);

        ;P;P;P BuggyMax

        M 1 Reply Last reply
        0
        • M Maxwell Chen

          :confused: :confused: :confused: Comma is used heavily in our code... while you declaring functions. For example:

          void Foo(int iNumber, bool bFlag);
          BOOL Move(HWND hWnd, LONG x, LONG y, ULONG cx, ULONG cy);

          ;P;P;P BuggyMax

          M Offline
          M Offline
          Marissa182
          wrote on last edited by
          #4

          im talking about where semi colons are used like this void main() { function(), function2(), function3(); }

          M 1 Reply Last reply
          0
          • M Marissa182

            how come the comma operator isnt used more often i was able to write a whole function using 1 semi color at the end so how come people dont use the commas? is there a performance reason or somethting?

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

            Because commas are used for other things. Semicolons are used for the end of a statement, so why not use them? If you use commas, the code basically looks like one big function call. I'm not sure why you'd want to use commas over semicolons.

            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"

            1 Reply Last reply
            0
            • M Marissa182

              im talking about where semi colons are used like this void main() { function(), function2(), function3(); }

              M Offline
              M Offline
              Maxwell Chen
              wrote on last edited by
              #6

              #include <iostream>

              int SetVal_1(int iNum)
              {
              return iNum +1;
              }

              int SetVal_2(int iNum)
              {
              return iNum * 2;
              }

              int SetVal_3(int iNum)
              {
              return iNum * 3 + 4;
              }

              void main()
              {
              int LuckyNum = SetVal_1(5), SetVal_2(6), SetVal_3(7);

              printf("Lucky number = %d\\n", LuckyNum);
              

              }

              BuggyMax

              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