|
-
Jun 4th, 2011, 07:41 AM
#1
Thread Starter
Hyperactive Member
confused with Handle pointer
Hi Folks
Pointers in C is something I always end up confusing myself with...
I have a function that is passed a pointer to a handle. this function should then pass that pointer on to a sub-function.
Code:
int txSerial (HANDLE *hComm) {
// Do some stuff using *hComm here.
// EG.
if (*hComm == INVALID_HANDLE_VALUE) {
printf("Comm port returned an invalid handle\n");
return 1;
}
return 0;
}
int txSPI (HANDLE *hComm) {
return (txSerial(hComm)); //<<--- CONFUSED HERE.
}
int main (void) {
HANDLE hComm1;
int x;
// Assign a handle to hComm1.
x = txSPI(&hComm1);
return x;
}
My confusion is where I call the sub-function txSerial().
Should I be passing *hComm or hComm ???
Got my thinking all knotted up here, help much appreciated, Thanks
Last edited by wolf99; Jun 4th, 2011 at 07:47 AM.
Thanks 
-
Jun 4th, 2011, 07:50 AM
#2
Thread Starter
Hyperactive Member
Re: confused with Handle pointer
Im thinking it should be hComm not *hComm
As to pass it *hComm would be to pass the data stored at the location pointed to by hComm (ie the HANDLE itself) rather than passing the address of that location....
Is that correct or have I got it arse-ways?
Thanks 
-
Jun 4th, 2011, 08:19 AM
#3
Re: confused with Handle pointer
You're right.
Since hComm in txSPI is already a pointer to a handle, you should pass it as-is to txSerial.
*hComm would dereference the pointer, leaving you with the handle it points to.
-
Jun 4th, 2011, 08:46 AM
#4
Thread Starter
Hyperactive Member
Re: confused with Handle pointer
Thanks Athiest
Thanks 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|