Geek Help!
Sep. 20th, 2005 08:21 amOK guys,
The OS class is giving me a pointer problem that's making me nuts. I'm sure some of this is that I'm so damn rusty at C coding. Here's the deal:
The calling function passes an argument (Z509_REG1 which is an INT32 type) to the function GET_TIME_OF_DAY
GET_TIME_OF_DAY assigns it's own "argument register" to the space allocated to that argument (which it accepted as arg1):
Z502_REG_ARG1.PTR = (void *)arg1;
This is a union, whose declaration looks like this:
typedef union
{
void *PTR;
INT32 VAL;
} Z502_ARG;
Now... I have a service call underneath all this that actually uses our 'hardware' to get the time of day (no problem, got it - as an INT32). And I need to send this information back - via Z502_REG_ARG1.
Since the original call expects a specific address, the challenge is - getting the value into the Z502_REG_ARG1 pointer, without changing the location of the pointer's address. I'd have thought that would be:
(INT32 *)Z502_REG_ARG1.PTR = os_get_time();
Where os_get_time() is the function I'm using to get the time from the hardware.
But that doesn't get the value where it needs to go. I've tried a couple other permutations, but I'm out of ideas.
The OS class is giving me a pointer problem that's making me nuts. I'm sure some of this is that I'm so damn rusty at C coding. Here's the deal:
The calling function passes an argument (Z509_REG1 which is an INT32 type) to the function GET_TIME_OF_DAY
GET_TIME_OF_DAY assigns it's own "argument register" to the space allocated to that argument (which it accepted as arg1):
Z502_REG_ARG1.PTR = (void *)arg1;
This is a union, whose declaration looks like this:
typedef union
{
void *PTR;
INT32 VAL;
} Z502_ARG;
Now... I have a service call underneath all this that actually uses our 'hardware' to get the time of day (no problem, got it - as an INT32). And I need to send this information back - via Z502_REG_ARG1.
Since the original call expects a specific address, the challenge is - getting the value into the Z502_REG_ARG1 pointer, without changing the location of the pointer's address. I'd have thought that would be:
(INT32 *)Z502_REG_ARG1.PTR = os_get_time();
Where os_get_time() is the function I'm using to get the time from the hardware.
But that doesn't get the value where it needs to go. I've tried a couple other permutations, but I'm out of ideas.
And the answer is...
Apparently by doing just (INT32 *) I was casting, but not dereferencing the pointer, I need to dereference it too.
That's just evil.
Why is it that you only get the answer after you've raised your hand to ask for help? :)
Re: And the answer is...
Date: 2005-09-20 01:47 pm (UTC)