It will work. The function will initialize the x and y fields of the structure as if it were a shape. I've seen many projects that use something similar to that, they create several structures with the same first field to differentiate between them (take a look at the love game, written by quel solaar) and it's actually quite useful if you use it wisely.
However I'd do it differently. When the initial data is the same, I'd actually modify the Rectangle structure like this:
typedef struct {
Shape s;
int w, h;
} Rectangle;
This way, when you call the init function you can either typecast the rectangle as a shape or pass the internal Shape s to the function. In my mind it makes it clearer.
Going further I'd do something more similar to this:
#include <stdint.h>
#define TYPE_SHAPE 0U
#define TYPE_RECTANGLE 1U
typedef struct {
char *name;
char *descrition;
uit8_t type;
} Info;
typedef struct {
Info info;
int x, y;
} Shape;
typedef struct {
Info info;
Shape s;
int w,h;
}
void Init(Info *block) {
if(block->type == TYPE_SHAPE) {
//initialize it
} else {
//do something elese
}
}
Even better I'd use an enum instead of a define for the type, and the field would change to an enum, but for this size I think it's ok that way.
But again, answering your question again, IF the x and y fields of both the rectangle and shape mean the same thing, then your way will work without any problems.
PS: I haven't compiled the above to test if it works, it's just to give an idea.