parameter question
-
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: -
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: -
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); };
-
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:What's strange about it? The second parameter to the
add()
method is expected to be achar*
.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
-
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: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
-
What's strange about it? The second parameter to the
add()
method is expected to be achar*
.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
-
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: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! ]
-
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
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: -
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! ]
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| -
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
-
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: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
-
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: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