I want to add a field to a structure in C. So for example I have the following structure.
struct A
{
some_type x;
some_type y;
}
I declare a new structure, like this.
struct B
{
A a;
some_type z;
}
Now say I have a function like this.
int some_function( A * a )
Is it possible to pass a variable of type B to it like this in the program.
B * b;
......
A * a = (A*)b;
some_function( a );
And also be able to use the fields inside some_function by using a->x for example?
Yes, it is valid. Word of the Standard, C99 6.7.2.1/13: