Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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

Status
Not open for further replies.

rob1012

Junior Member level 3
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
return value of pointer

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.:cry:
 

return value from pointer

HI

Try this :

void FunctionCall(void)
{
//Define dat as variable
unsigned char Dat ;
//Send dat as ref
passByRef(&Dat);

//process the value of Dat
If(dat < 9)
{
Dat = Dat /2
}

}


void passByRef(unsigned char *Dat)
{
//Load Dat with new value
Dat = 9;

}

All the best

Bobi
 

return value or pointer

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:

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top