On Thu, 17 Jul 2003 11:11:26 +0100, "Steven Graham" <>
wrote:
> What is
>going on. BTW this little psudo-C code summarises my problem. (main is at
>the bottom if you want to start following from there)
<snipped pseudocode>
Pseudocode rarely helps in these type of problems. I have fleshed out
your code into something compilable by Comeau. I've included the
output below.
typedef struct
{
char item1;
int item2;
} A_STRUCT;
void function2(A_STRUCT *dest_struct)
{
//Put these into the strict that was called by reference
dest_struct->item1 = 'A';
dest_struct->item2 = 1000;
printf("f2: %c\n", dest_struct->item1); //Yey it changed!
}
void function1(void)
{
A_STRUCT my_struct = {'B', 1};
printf("f1: %c\n", my_struct.item1);
// This shows my original non-junk values
//now populate the struct
function2(&my_struct);
printf("f1: %c\n", my_struct.item1);
// It has have changed!!
}
int main(void)
{
function1();
return 0;
}
Output:
f1: B
f2: A
f1: A
It seems to work fine here. I would avoid the undefined behavior that
you invoked by not initializing your structure. Is there a difference
between your real code and my code?
Best wishes,
Bob
|