S
Sam
Hi everyone
I'm confused by these declarations:
struct hostent *he;
server *s = (server*)malloc(sizeof(server));
/* in the code *
he = gethostbyname(name);
(server is defined in the include as
typedef struct {
int fdin, fdout;
FILE *fin, *fout;
} server;
)
Am I right in thinking that both *he and *s are pointers to structures? In
that case, how come memory is only allocated for *s and not *he? When the
members of *he are accessed later on in the code, where does the memory
come from? What rules govern when you need to malloc and when you don't?
Many thanks for advice
Sam
I'm confused by these declarations:
struct hostent *he;
server *s = (server*)malloc(sizeof(server));
/* in the code *
he = gethostbyname(name);
(server is defined in the include as
typedef struct {
int fdin, fdout;
FILE *fin, *fout;
} server;
)
Am I right in thinking that both *he and *s are pointers to structures? In
that case, how come memory is only allocated for *s and not *he? When the
members of *he are accessed later on in the code, where does the memory
come from? What rules govern when you need to malloc and when you don't?
Many thanks for advice
Sam