Swede,
I'm pretty sure you've simply done something wrong.
Try the code below. You'll see that the shape struct is declared globally, and that each time the program calls sizer(), the values of the static circle (is-a relationship) shape are retained. That can only mean one thing - you aren't incrementing your variables, or the code that does is being skipped due to the values of your conditional operands.
Remember to use your watch, trace and assert debugging methods
![](smile.gif)
void sizer(void);
struct shape{
int radius;
int diameter;
};
int main(int argc, char* argv[])
{
for (int x = 0; x < 5; x++)
sizer();
return 0;
}
void sizer(void)
{
static shape circle = {4, circle.radius*2};
printf("size %d\n", circle.radius);
printf("diameter %d\n", circle.diameter);
circle.radius++;
circle.diameter++;
}
Output:
size 4
diameter 8
size 5
diameter 9
size 6
diameter 10
size 7
diameter 11
size 8
diameter 12
Edited by - videns on June 16, 2001 8:07:52 PM