HELP!!! how to return a value using pointer function?

Status
Not open for further replies.

rob1012

Junior Member level 3
Joined
Mar 27, 2007
Messages
31
Helped
3
Reputation
6
Reaction score
4
Trophy points
1,288
Activity points
1,477
i have a code like this


hal_usb_dev_req_resp_t device_req_cb(hal_usb_device_req* req, uint8_t** data_ptr) reentrant
{
hal_usb_dev_req_resp_t* resp;

hal_usb_hid_device_req_proc(req, &data_ptr, &resp);
return resp;
}

void hal_usb_hid_device_req_proc(hal_usb_device_req* req, uint8_t** data_ptr, hal_usb_dev_req_resp_t* resp)
{
*data_ptr = &string_of_data;
*resp = DATA;
}

this is pass by reference using pointers right? I cant pass the &string_of_data to the device_req_cb. im weirded out already.. please help.
 

You can also view a pointer to a pointer as a pointer to an array of pointers, same thing. You dont have to de-reference it before passing it to your function.
You de-reference it in the function.
Either as an array, 'data_ptr[x]' or as an offset, '*(data_ptr + x)'

Code:
int main(void)
{
char **data_ptr;

data_ptr[0] = "hello";		/* Pointers to strings */
data_ptr[1] = "Goodbye";
data_ptr[2] = "World";

req_proc(data_ptr);
return 0;
}

void req_proc(char **data_ptr)
{
char *temp;
char *Data = "Cruel"; /* Pointer to string */

data_ptr[0] = Data;

Data = data_ptr[1];

temp = *(data_ptr + 2);	/* Another way */
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…