S
Stephen Kershaw
Hi,
I know some basic C and am currently trying to understand some source code.
I enclose some relevant snippets of code below.
My question is this:
The code creates a large array of chars, called t_data. The first 10
spaces are then filled with characters.
However, the line:
params = (struct param *)&t_data;
then, I think (not entirely sure), creates a variable of type param
(struct defined elsewhere), starting at the address of the start of t_data?
So, to my mind the values previously written to t_data are overwritten
so there is no point to the code filling the first 10 entries of the
array? Is this correct?
Hopefully I have provided enough context below,
Many thanks,
Stephen
(... represents cropped code)
(the struct param is defined in a .h file, structure of ints and chars)
#define T_DATA_MAX 10000000
unsigned char t_data[T_DATA_MAX];
struct param *params;
....
for(i=0; i<10; i++)
{
t_data = i;
}
....
params = (struct param *)&t_data;
I know some basic C and am currently trying to understand some source code.
I enclose some relevant snippets of code below.
My question is this:
The code creates a large array of chars, called t_data. The first 10
spaces are then filled with characters.
However, the line:
params = (struct param *)&t_data;
then, I think (not entirely sure), creates a variable of type param
(struct defined elsewhere), starting at the address of the start of t_data?
So, to my mind the values previously written to t_data are overwritten
so there is no point to the code filling the first 10 entries of the
array? Is this correct?
Hopefully I have provided enough context below,
Many thanks,
Stephen
(... represents cropped code)
(the struct param is defined in a .h file, structure of ints and chars)
#define T_DATA_MAX 10000000
unsigned char t_data[T_DATA_MAX];
struct param *params;
....
for(i=0; i<10; i++)
{
t_data = i;
}
....
params = (struct param *)&t_data;