static aray question?
Hello,
I am doing some tests in C, in VC++. I am coding stuff but I don't know if
this is acceptable from a proffessional point of view. Please consider the
following snippet:
====================================
#include <stdio.h>
#include <stdlib.h>
typedef struct i{
short v; // I thought we used to be able to use bool type ?????
}w;
typedef struct z{
int x;
w *xxx;
}f;
f *f1(f *h)
{
static w x[] = {1,0,1,1,1,0,0,1,0,0};
h = malloc(sizeof(f));
h->x = 8;
h->xxx = x;
return h;
}
main()
{
int t=0;
f *g;
g=f1(g);
t = g->x;
t = g->xxx[4].v;
free(g);
}
============================================
Questions:
1) Is the contents of the static x[] array is stored in the stack?
2) Once the f1() function is executed, the static array x[] will always live
and its contents will always stay in memory until main ends, right?
3) My concern is the above programming method involving the array and all,
reccomended? In other words in your opinion is calling data from an array
this way right or wrong.
4) I also get the following warning saying that g is uninnitialized. Since g
is only innitialized in f1() function is this an extremely important warning?
Thankyou for your feedback!
Excuse me if my questions are basic and sometimes repetitive, but,
unfortunately they are questions that I need extra clarification on!
--
Best regards
Roberto