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. parameter question

parameter question

Scheduled Pinned Locked Moved C / C++ / MFC
question
15 Posts 7 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.
  • J Offline
    J Offline
    Jay03
    wrote on last edited by
    #1

    pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount)); the second parameter looks strange...... haven't dealt with those before.... What's the function of that? [ (char *)&changeAmount ] :wtf:

    V A D C T 6 Replies Last reply
    0
    • J Jay03

      pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount)); the second parameter looks strange...... haven't dealt with those before.... What's the function of that? [ (char *)&changeAmount ] :wtf:

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      reinterpret_cast() int x = 0 // 4 bytes on 32-bit char *p = reinterpret_cast(&x) Kuphryn

      J A 2 Replies Last reply
      0
      • V valikac

        reinterpret_cast() int x = 0 // 4 bytes on 32-bit char *p = reinterpret_cast(&x) Kuphryn

        J Offline
        J Offline
        Jay03
        wrote on last edited by
        #3

        im lost....... not to mention imma beginner:laugh:

        1 Reply Last reply
        0
        • J Jay03

          pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount)); the second parameter looks strange...... haven't dealt with those before.... What's the function of that? [ (char *)&changeAmount ] :wtf:

          A Offline
          A Offline
          Alex_Y
          wrote on last edited by
          #4

          what is type of changeAmount?

          :)

          J 1 Reply Last reply
          0
          • A Alex_Y

            what is type of changeAmount?

            :)

            J Offline
            J Offline
            Jay03
            wrote on last edited by
            #5

            its an integer void ChangeBallVelocity(int changeAmount) { RTI::ParameterHandleValuePairSet* pParams = NULL; pParams = RTI::ParameterSetFactory::create( 1 ); pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount)); rtiAmb.sendInteraction(velocityId, *pParams, NULL); delete pParams; } This is very confusing.... What is pParams assigning? class RTI_EXPORT ParameterSetFactory { public: static ParameterHandleValuePairSet* create(ULong count) throw ( MemoryExhausted, ValueCountExceeded, HandleValuePairMaximumExceeded); };

            1 Reply Last reply
            0
            • J Jay03

              pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount)); the second parameter looks strange...... haven't dealt with those before.... What's the function of that? [ (char *)&changeAmount ] :wtf:

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

              What's strange about it? The second parameter to the add() method is expected to be a char*. changeAmount is some other type, hence the cast.


              "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

              "Judge not by the eye but by the heart." - Native American Proverb

              A 1 Reply Last reply
              0
              • J Jay03

                pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount)); the second parameter looks strange...... haven't dealt with those before.... What's the function of that? [ (char *)&changeAmount ] :wtf:

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                Jay03 wrote:

                (char *)&changeAmount

                This means that changeAmount is a variable. & turns it into a pointer. So, if changeAmount was an int, &changeAmount is an int *. Then whatever sort of pointer it is, it gets cast to a char *. Now, one has to presume this means it wasn't a char* to start with, but that this cast is valid.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                J 2 Replies Last reply
                0
                • D David Crow

                  What's strange about it? The second parameter to the add() method is expected to be a char*. changeAmount is some other type, hence the cast.


                  "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                  "Judge not by the eye but by the heart." - Native American Proverb

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

                  Dave did you see address of what they are taking and what is going to happen later. But reinterpret_cast solution was the best:)

                  :)

                  1 Reply Last reply
                  0
                  • V valikac

                    reinterpret_cast() int x = 0 // 4 bytes on 32-bit char *p = reinterpret_cast(&x) Kuphryn

                    A Offline
                    A Offline
                    Alex_Y
                    wrote on last edited by
                    #9

                    Actualy I knew one gentelman who casted CString* to CDocument* using reinterpret_cast. Great!

                    :)

                    1 Reply Last reply
                    0
                    • J Jay03

                      pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount)); the second parameter looks strange...... haven't dealt with those before.... What's the function of that? [ (char *)&changeAmount ] :wtf:

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

                      even Christian already gave you a valuable answer, here is another way to understand it. in the expression (char*)&changeAmount, there are 2 operators called : 1. unary & usually called "address of" and used to get the address of changeAmount 2. (char*) is a cast operator, which explicits the cast of an address previously got with 1. into a char* doing this changes the type of the pointer on the base address of changeAmount, so that it can be access each byte of that variable.


                      TOXCCT >>> GEII power

                      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                      J 1 Reply Last reply
                      0
                      • C Christian Graus

                        Jay03 wrote:

                        (char *)&changeAmount

                        This means that changeAmount is a variable. & turns it into a pointer. So, if changeAmount was an int, &changeAmount is an int *. Then whatever sort of pointer it is, it gets cast to a char *. Now, one has to presume this means it wasn't a char* to start with, but that this cast is valid.

                        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                        J Offline
                        J Offline
                        Jay03
                        wrote on last edited by
                        #11

                        sorry to ask such a silly question but

                        Christian Graus wrote:

                        So, if changeAmount was an int, &changeAmount is an int *.

                        So does this mean (char*) & changeAmount equivalent to : (char *) * int ChangeAmount So this means, changeAmount was a pointer to an integer and is now changed to a pointer to a character? :confused:

                        C 1 Reply Last reply
                        0
                        • T toxcct

                          even Christian already gave you a valuable answer, here is another way to understand it. in the expression (char*)&changeAmount, there are 2 operators called : 1. unary & usually called "address of" and used to get the address of changeAmount 2. (char*) is a cast operator, which explicits the cast of an address previously got with 1. into a char* doing this changes the type of the pointer on the base address of changeAmount, so that it can be access each byte of that variable.


                          TOXCCT >>> GEII power

                          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                          J Offline
                          J Offline
                          Jay03
                          wrote on last edited by
                          #12

                          sorry to bother u but it makes sense to say changeAmount is an integer pointer and we want to cast it to a char pointer. But in our case changeAmount is NOT an integer pointer, its rather has the address of changeAmount (&changeAmount) ..... how can this be changed into a character pointer now. it makes sense if it was like this: (char*) int *changeAmount pls get me running on the right track.. haha thanks X|

                          1 Reply Last reply
                          0
                          • C Christian Graus

                            Jay03 wrote:

                            (char *)&changeAmount

                            This means that changeAmount is a variable. & turns it into a pointer. So, if changeAmount was an int, &changeAmount is an int *. Then whatever sort of pointer it is, it gets cast to a char *. Now, one has to presume this means it wasn't a char* to start with, but that this cast is valid.

                            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                            J Offline
                            J Offline
                            Jay03
                            wrote on last edited by
                            #13

                            Christian Graus wrote:

                            & turns it into a pointer

                            how does & turn into a pointer.........:doh:

                            1 Reply Last reply
                            0
                            • J Jay03

                              pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount)); the second parameter looks strange...... haven't dealt with those before.... What's the function of that? [ (char *)&changeAmount ] :wtf:

                              Z Offline
                              Z Offline
                              Zac Howland
                              wrote on last edited by
                              #14

                              The function "add" has a second parameter that appears to take bytes as its type (an array of bytes actually). The & operator takes the address of a variable (that is, gives you a pointer to it) and the (char*) casts it to a charater pointer type. What it is doing is passing in the array of bytes for that variable (the size is passed as the third argument) to do something with them directly (e.g. transmit them over the network perhaps?).

                              If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                              1 Reply Last reply
                              0
                              • J Jay03

                                sorry to ask such a silly question but

                                Christian Graus wrote:

                                So, if changeAmount was an int, &changeAmount is an int *.

                                So does this mean (char*) & changeAmount equivalent to : (char *) * int ChangeAmount So this means, changeAmount was a pointer to an integer and is now changed to a pointer to a character? :confused:

                                C Offline
                                C Offline
                                Christian Graus
                                wrote on last edited by
                                #15

                                No, it means that IF changeAmount was an int, then the & syntax turns it into a pointer, but that would then be an int *. A cast changes the type, in this case, to char *. That's what the & sytnax does, it returns the address of a variable. And a cast changes a variable type.

                                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                                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