I have this function:
void myFunct(const int A, ?out? int B){B = B + A;}
How to declare B in such a way that the function can update its value and return it to the caller?
Metal is a C++ based programming language that allows you to pass a pointer to a function. To do so, simply declare the function parameter as a pointer type.
void myFunct(const int A, device int *B)
{
*B = *B + A;
}
device int *C = 0;
myFunct(1, C);
You can also pass variable by reference:
void myFunct(const int A, device int &B)
{
B = B + A;
}
device int *C = 0;
myFunct(1, *C)
or pointer by reference:
void myFunct(const int A, device int *&B)
{
*B = *B + A;
}
device int *C = 0;
myFunct(1, C);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.