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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Please help

Please help

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
10 Posts 6 Posters 1 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.
  • R Offline
    R Offline
    rajeevktripathi
    wrote on last edited by
    #1

    Hi How to change associativity of operators in C++, e.g. if we have int a = 15; int b = 5; int c = a---b; then compiler interpret this expression as int c = (a--) - b; what I want, is like int c = a -(--b); is there any way to achieve this. Please suggest me. Thanks & Regards

    N B T D 4 Replies Last reply
    0
    • R rajeevktripathi

      Hi How to change associativity of operators in C++, e.g. if we have int a = 15; int b = 5; int c = a---b; then compiler interpret this expression as int c = (a--) - b; what I want, is like int c = a -(--b); is there any way to achieve this. Please suggest me. Thanks & Regards

      N Offline
      N Offline
      nbugalia
      wrote on last edited by
      #2

      Use proper parenthesis in your code.

      1 Reply Last reply
      0
      • R rajeevktripathi

        Hi How to change associativity of operators in C++, e.g. if we have int a = 15; int b = 5; int c = a---b; then compiler interpret this expression as int c = (a--) - b; what I want, is like int c = a -(--b); is there any way to achieve this. Please suggest me. Thanks & Regards

        B Offline
        B Offline
        baerten
        wrote on last edited by
        #3

        I don't think so. Because the compiler doesn't know your minds. All automatic parsing is defined by rules. Like mathematics, if you calculate 5+5*6 you should begin with 5*6 and then + 5 if you specifie it (5+5)*6 you start with adding 5+5 then the *6 It's the same in programmation. :)

        R 1 Reply Last reply
        0
        • B baerten

          I don't think so. Because the compiler doesn't know your minds. All automatic parsing is defined by rules. Like mathematics, if you calculate 5+5*6 you should begin with 5*6 and then + 5 if you specifie it (5+5)*6 you start with adding 5+5 then the *6 It's the same in programmation. :)

          R Offline
          R Offline
          rajeevktripathi
          wrote on last edited by
          #4

          Hi thanks for your replies Is there any prgma option to do this please suggest me Thans & regards

          N J 2 Replies Last reply
          0
          • R rajeevktripathi

            Hi thanks for your replies Is there any prgma option to do this please suggest me Thans & regards

            N Offline
            N Offline
            nbugalia
            wrote on last edited by
            #5

            rajeevktripathi wrote:

            Is there any prgma option to do this

            I didn't found any.

            T 1 Reply Last reply
            0
            • R rajeevktripathi

              Hi thanks for your replies Is there any prgma option to do this please suggest me Thans & regards

              J Offline
              J Offline
              jhwurmbach
              wrote on last edited by
              #6

              rajeevktripathi wrote:

              Is there any prgma option to do this

              No. There is no need for that. You write the parenthesis in your code where you need them. When in doubt, add a pair of parenthesis. Extra pairs of parenthesis won't do any harm.


              Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
              George Orwell, "Keep the Aspidistra Flying", Opening words

              T 1 Reply Last reply
              0
              • R rajeevktripathi

                Hi How to change associativity of operators in C++, e.g. if we have int a = 15; int b = 5; int c = a---b; then compiler interpret this expression as int c = (a--) - b; what I want, is like int c = a -(--b); is there any way to achieve this. Please suggest me. Thanks & Regards

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                rajeevktripathi wrote:

                How to change associativity of operators in C++,

                changing associativity is like changing the meaning of things (so, changing the language itself), so, no way at all. moreover, if associativity exists like it is, there are reasons over the problem you can have with it.

                rajeevktripathi wrote:

                then compiler interpret this expression as int c = (a--) - b; what I want, is like int c = a -(--b);

                then, why don't you just use spaces (or at least, parenthises like someone said) ? write c = a - --b; and everything will be good.


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                1 Reply Last reply
                0
                • N nbugalia

                  rajeevktripathi wrote:

                  Is there any prgma option to do this

                  I didn't found any.

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #8

                  NishantB++ wrote:

                  I didn't found any.

                  of course you didn't, 'cause there aren't any ! this feature is a fundamental of the language itself !!!


                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                  1 Reply Last reply
                  0
                  • J jhwurmbach

                    rajeevktripathi wrote:

                    Is there any prgma option to do this

                    No. There is no need for that. You write the parenthesis in your code where you need them. When in doubt, add a pair of parenthesis. Extra pairs of parenthesis won't do any harm.


                    Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                    George Orwell, "Keep the Aspidistra Flying", Opening words

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #9

                    jhwurmbach wrote:

                    Extra pairs of parenthesis won't do any harm

                    no need. one pair is largely sufficient, because it can be countered with simple spaces...


                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                    1 Reply Last reply
                    0
                    • R rajeevktripathi

                      Hi How to change associativity of operators in C++, e.g. if we have int a = 15; int b = 5; int c = a---b; then compiler interpret this expression as int c = (a--) - b; what I want, is like int c = a -(--b); is there any way to achieve this. Please suggest me. Thanks & Regards

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      rajeevktripathi wrote:

                      is there any way to achieve this.

                      Why make things harder than necessary:

                      int a = 15;
                      int b = 5;
                      a--;
                      --b;
                      int c = a-b;


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      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