Initialize the structure of other structure
Can i initialize structure if other structure? For example: I have structure:
typedef struct _JobParam
{
MainWin* mw;
}JobParam;
Where MainWin structure too.
In main code i have function:
Can the so-initialize structure or it's wrong way?
void load (MainWin* mw)
{
Para开发者_StackOverflowm param;
param.mw = mw;
}
Thank you
Well, in the case you're showing, it's just a pointer that's getting copied so that's fine. If they were structures, it would also be ok... gcc
will emit a call to memcpy
in that case (at least often), but the C standard does allow structure copying:
struct s { int x; int y };
struct s a = { 3, 4 };
struct s b = a;
精彩评论