开发者

Initialize the structure of other structure

开发者 https://www.devze.com 2023-01-04 16:06 出处:网络
Can i initialize structure if other structure? For example: I have structure: typedef struct _JobParam

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号