I have been wondering, what does &functionname do in your program? I wanted the robot to do something if a program was running. I typed the function name into my if statement as my condition, and it highlighted it in green and gave me a fix. It said this: “prefix with the address-of operator to silence this warning” when I clicked on the suggested fix, it displayed my function with an added &
at the beginning. I figured that would fix my problem and everything would run fine, but it didn’t. I wanted to know what this was but could not find anything relevant on the internet. I used it like so:
if (&functionname) {
//Do something
}
I hypothesized that it might mean “if this function is running, then do something”. But I may be wrong. There are many ways I can use it if I am correct but I should discard it if I am not. Has somebody used this before and know what it means?
The ampersand (&
) is known as the address-of operator. It is used in the context of pointers.
Learn more about pointers and the address-of operator here:
http://www.cplusplus.com/doc/tutorial/pointers/
3 Likes
Nope, the way you are using it more or less means “if the function exists”, but it’s sort of pointless in the context of writing code for a VEX robot. There are situations where it is used, but that’s quite advanced use.
5 Likes
Ok. Thank you all! I will discard it as it is not needed anymore. Hope you all have happy holidays!
1 Like