FINAL EDIT: First of all, thank you guys for your patience. In the future I'll try to bring an MCVE to any questions I ask.
The program seems to be working fine now - I may have unwittingly deleted a typo or something.
This question annoys me quite a bit - I didn't choose to implement it this way, but it's required and I need to resolve it.
I've got a function that's supposed to read a piece of data from a struct, like this:
typedef struct {
int data;
char extraneous_stuff[];
} MyStruct;
...
//there's also a ParentStruct that holds a MyStruct array
...
void read_data(ParentStruct *parent, int which_MyStruct, int *data) {...
What I need to do is use the int *data as an out-parameter to copy the int data from inside a selected MyStruct. The problem I'm having, of course, is that both the out-parameter and the MyStruct field have exactly the same name. I found that trying to copy directly, i.e. *data = parent->array[which_MyStruct].data;
compiled, but the data didn't actually get copied to the out parameter.
In order to hold to specifications I'm not supposed to change the names of the parameters here. Am I doomed?
EDIT: I included the following print statements inside the function:
printf("%d", *data);
printf("%d", parent->array[which_MyStruct].data);
and, having put
int n = 0;
void read_data(*parent, which_MyStruct, &n)
I got back
0
0
as a result.
EDIT 2:
OK, this is very weird. I have this:
MyStruct current = parent->array[which_MyStruct];
printf("%s", current.extraneous_stuff[0]);
printf("%d", *data);
printf("%d", parent->array[which_MyStruct].data);
and now suddenly "parent->array[which_MyStruct].data" has the appropriate value. Maybe this is undefined behavior, because the only change I made was to include the print statement "printf("%s", current.extraneous_stuff[0]);" and the output changed.