Re: nested structures and initialization



On Wed, 31 Oct 2007 09:18:29 -0000, Sheldon <shejo284@xxxxxxxxx>
wrote:

Can anyone help with this problem with setting up nested structures
and initializing them for use.
I have created several structs and placed them in a super struct that
I will then pass to some functions. I have defined them in the
following manner:

<snip>

typedef struct super Super;

<snip>
struct super {
Transient *TR;
Satellites *Sp;
Satellites *Su;
Satellites *Au;
Satellites *Wi;
};

<snip>

Super *InitStruct(void) {

Super *sptr=NULL;

if(!(sptr=malloc(sizeof(Super)))) {
return NULL;
}

<snip remainder>

Well the first thing that leaps out is that you've allocated space for
a "struct super", which is simply five pointers. Nowhere do you
allocate the memory that those pointers point at. I'm not even going
to try and see what else is wrong :-)
--
PGP key ID 0xEB7180EC
.



Relevant Pages