views:

27

answers:

1

Hello,

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)
{
   Param param;
   param.mw = mw;
}

Thank you

+1  A: 

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;
Carl Norum