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. C++ expression(s)

C++ expression(s)

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++question
13 Posts 10 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.
  • C Offline
    C Offline
    C3D1
    wrote on last edited by
    #1

    Today i found some really weird expression in some C++-code

    if(++(k=j) != node.end())
    {
    if("something" == *k)
    doSomething();
    else if("something other" == *k)
    doSomethingOther();
    }

    and just ~30 lines below that weird if statement i found this:

    k = j;
    if(++k != node.end())

    {
    if("something" == *k)
    doSomething();
    else if("something other" == *k)
    doSomethingOther();
    }

    why always so weird? Why don' to it in an nice way

    k = j + 1;
    if(k != node.end())

    {
    if("something" == *k)
    doSomething();
    else if("something other" == *k)
    doSomethingOther();
    }

    In some other code a few days ago i found this

    n[idx++] = a[++idx2]++;

    where both, a and n, are defined as void* What are the ugliest C++ expressions that have you seen in the last few weeks/months

    M I L P D 5 Replies Last reply
    0
    • C C3D1

      Today i found some really weird expression in some C++-code

      if(++(k=j) != node.end())
      {
      if("something" == *k)
      doSomething();
      else if("something other" == *k)
      doSomethingOther();
      }

      and just ~30 lines below that weird if statement i found this:

      k = j;
      if(++k != node.end())

      {
      if("something" == *k)
      doSomething();
      else if("something other" == *k)
      doSomethingOther();
      }

      why always so weird? Why don' to it in an nice way

      k = j + 1;
      if(k != node.end())

      {
      if("something" == *k)
      doSomething();
      else if("something other" == *k)
      doSomethingOther();
      }

      In some other code a few days ago i found this

      n[idx++] = a[++idx2]++;

      where both, a and n, are defined as void* What are the ugliest C++ expressions that have you seen in the last few weeks/months

      M Offline
      M Offline
      megaadam
      wrote on last edited by
      #2

      C3D1 wrote:

      why always so weird?

      Hmmm... isn't that a programming question ? :cool: [EDIT: Silly me! I thought we were in the Lounge ;P ] I think some people write such nasty stuff because it makes them feel smart. And maybe, a few of them think that it compiles into faster code :wtf:

      Life is too shor

      D 1 Reply Last reply
      0
      • M megaadam

        C3D1 wrote:

        why always so weird?

        Hmmm... isn't that a programming question ? :cool: [EDIT: Silly me! I thought we were in the Lounge ;P ] I think some people write such nasty stuff because it makes them feel smart. And maybe, a few of them think that it compiles into faster code :wtf:

        Life is too shor

        D Offline
        D Offline
        den2k88
        wrote on last edited by
        #3

        The shorter the code the faster it gets... thrown out of the window along with the programmer :suss: I sometimes write artworks like that but in 5 minutes I expand them to the readable form. It's just better.

        GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver "When you have eliminated the JavaScript, whatever remains must be an empty page." -- Mike Hankey

        1 Reply Last reply
        0
        • C C3D1

          Today i found some really weird expression in some C++-code

          if(++(k=j) != node.end())
          {
          if("something" == *k)
          doSomething();
          else if("something other" == *k)
          doSomethingOther();
          }

          and just ~30 lines below that weird if statement i found this:

          k = j;
          if(++k != node.end())

          {
          if("something" == *k)
          doSomething();
          else if("something other" == *k)
          doSomethingOther();
          }

          why always so weird? Why don' to it in an nice way

          k = j + 1;
          if(k != node.end())

          {
          if("something" == *k)
          doSomething();
          else if("something other" == *k)
          doSomethingOther();
          }

          In some other code a few days ago i found this

          n[idx++] = a[++idx2]++;

          where both, a and n, are defined as void* What are the ugliest C++ expressions that have you seen in the last few weeks/months

          I Offline
          I Offline
          Indivara
          wrote on last edited by
          #4

          My favourite is the --> "operator".

          int counter = 10;
          while (counter --> 0)
          {
          // do something
          }

          Some people consider it ugly.

          D A P C 4 Replies Last reply
          0
          • I Indivara

            My favourite is the --> "operator".

            int counter = 10;
            while (counter --> 0)
            {
            // do something
            }

            Some people consider it ugly.

            D Offline
            D Offline
            den2k88
            wrote on last edited by
            #5

            It's... wonderful. And weird.

            GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver "When you have eliminated the JavaScript, whatever remains must be an empty page." -- Mike Hankey

            1 Reply Last reply
            0
            • C C3D1

              Today i found some really weird expression in some C++-code

              if(++(k=j) != node.end())
              {
              if("something" == *k)
              doSomething();
              else if("something other" == *k)
              doSomethingOther();
              }

              and just ~30 lines below that weird if statement i found this:

              k = j;
              if(++k != node.end())

              {
              if("something" == *k)
              doSomething();
              else if("something other" == *k)
              doSomethingOther();
              }

              why always so weird? Why don' to it in an nice way

              k = j + 1;
              if(k != node.end())

              {
              if("something" == *k)
              doSomething();
              else if("something other" == *k)
              doSomethingOther();
              }

              In some other code a few days ago i found this

              n[idx++] = a[++idx2]++;

              where both, a and n, are defined as void* What are the ugliest C++ expressions that have you seen in the last few weeks/months

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

              C3D1 wrote:

              k = j + 1;

              That is a mistake. k obviously is a pointer and ++k will not increment this pointer by just 1 byte. It will increment it by the size of the type of k. Try it out and examine the memory address k points to in the debugger in both versions.

              The language is JavaScript. that of Mordor, which I will not utter here
              This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
              "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

              K 1 Reply Last reply
              0
              • L Lost User

                C3D1 wrote:

                k = j + 1;

                That is a mistake. k obviously is a pointer and ++k will not increment this pointer by just 1 byte. It will increment it by the size of the type of k. Try it out and examine the memory address k points to in the debugger in both versions.

                The language is JavaScript. that of Mordor, which I will not utter here
                This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
                "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

                K Offline
                K Offline
                k5054
                wrote on last edited by
                #7

                CDP1802 wrote:

                C3D1 wrote:

                k = j + 1;

                That is a mistake. k obviously is a pointer and ++k will not increment this pointer by just 1 byte. It will increment it by the size of the type of k. Try it out and examine the memory address k points to in the debugger in both versions.

                I think you're mistaken. k gets assigned j + sizeof(*j), not j + sizeof(*k). Hopefully j and k are compatible pointer types. Edit: I'm not sure what k = j + 1 has to do with ++k. In any case, ++k does not increment by the size of the type of k, but rather by the size of the type k references.

                1 Reply Last reply
                0
                • I Indivara

                  My favourite is the --> "operator".

                  int counter = 10;
                  while (counter --> 0)
                  {
                  // do something
                  }

                  Some people consider it ugly.

                  A Offline
                  A Offline
                  Agent__007
                  wrote on last edited by
                  #8

                  Brilliant! I actually Googled to find whether that "operator" really exists in C++! :doh:

                  You have just been Sharapova'd.

                  1 Reply Last reply
                  0
                  • I Indivara

                    My favourite is the --> "operator".

                    int counter = 10;
                    while (counter --> 0)
                    {
                    // do something
                    }

                    Some people consider it ugly.

                    P Offline
                    P Offline
                    Power Puff Boy
                    wrote on last edited by
                    #9

                    That's evil.

                    Kitty at my foot and I waAAAant to touch it...

                    1 Reply Last reply
                    0
                    • C C3D1

                      Today i found some really weird expression in some C++-code

                      if(++(k=j) != node.end())
                      {
                      if("something" == *k)
                      doSomething();
                      else if("something other" == *k)
                      doSomethingOther();
                      }

                      and just ~30 lines below that weird if statement i found this:

                      k = j;
                      if(++k != node.end())

                      {
                      if("something" == *k)
                      doSomething();
                      else if("something other" == *k)
                      doSomethingOther();
                      }

                      why always so weird? Why don' to it in an nice way

                      k = j + 1;
                      if(k != node.end())

                      {
                      if("something" == *k)
                      doSomething();
                      else if("something other" == *k)
                      doSomethingOther();
                      }

                      In some other code a few days ago i found this

                      n[idx++] = a[++idx2]++;

                      where both, a and n, are defined as void* What are the ugliest C++ expressions that have you seen in the last few weeks/months

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

                      Vile. Implementation-dependant. X|

                      1 Reply Last reply
                      0
                      • C C3D1

                        Today i found some really weird expression in some C++-code

                        if(++(k=j) != node.end())
                        {
                        if("something" == *k)
                        doSomething();
                        else if("something other" == *k)
                        doSomethingOther();
                        }

                        and just ~30 lines below that weird if statement i found this:

                        k = j;
                        if(++k != node.end())

                        {
                        if("something" == *k)
                        doSomething();
                        else if("something other" == *k)
                        doSomethingOther();
                        }

                        why always so weird? Why don' to it in an nice way

                        k = j + 1;
                        if(k != node.end())

                        {
                        if("something" == *k)
                        doSomething();
                        else if("something other" == *k)
                        doSomethingOther();
                        }

                        In some other code a few days ago i found this

                        n[idx++] = a[++idx2]++;

                        where both, a and n, are defined as void* What are the ugliest C++ expressions that have you seen in the last few weeks/months

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

                        C3D1 wrote:

                        What are the ugliest C++ expressions that have you seen in the last few weeks/months

                        In no particular order[1]:

                        #include "stdafx.h"

                        IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)

                        BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
                        //{{AFX_MSG_MAP(CMainFrame)

                        //}}AFX\_MSG\_MAP
                        
                        ON\_COMMAND(ID\_HELP, OnHelp)
                        

                        END_MESSAGE_MAP()

                        CMainFrame::CMainFrame()

                        [1] Oh who am I kidding, it's Friday and I'm just going down a file and pasting in the order found.

                        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                        C 1 Reply Last reply
                        0
                        • I Indivara

                          My favourite is the --> "operator".

                          int counter = 10;
                          while (counter --> 0)
                          {
                          // do something
                          }

                          Some people consider it ugly.

                          C Offline
                          C Offline
                          C3D1
                          wrote on last edited by
                          #12

                          isn't that a C++ 11 feature? I'm currently using the VC6 compiler... There is no C++ 11 :java: ;P

                          1 Reply Last reply
                          0
                          • D Dan Neely

                            C3D1 wrote:

                            What are the ugliest C++ expressions that have you seen in the last few weeks/months

                            In no particular order[1]:

                            #include "stdafx.h"

                            IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)

                            BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
                            //{{AFX_MSG_MAP(CMainFrame)

                            //}}AFX\_MSG\_MAP
                            
                            ON\_COMMAND(ID\_HELP, OnHelp)
                            

                            END_MESSAGE_MAP()

                            CMainFrame::CMainFrame()

                            [1] Oh who am I kidding, it's Friday and I'm just going down a file and pasting in the order found.

                            Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                            C Offline
                            C Offline
                            C3D1
                            wrote on last edited by
                            #13

                            Oh my god... The MFC MESSAGE_MAP... How could i miss this rape on #define-macros and the whole C++ Language...

                            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