Really odd pointer behavior
From: Mr. X (greenbaboon1_at_cox.net)
Date: 07/30/04
- Next message: Magix: "Bitwise operation"
- Previous message: Emmanuel Delahaye: "Re: rank and expressions"
- Next in thread: Ravi Uday: "Re: Really odd pointer behavior"
- Reply: Ravi Uday: "Re: Really odd pointer behavior"
- Reply: Barry Margolin: "Re: Really odd pointer behavior"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 29 Jul 2004 18:44:55 -0700
Hello all,
Please advise...
Consider the following...
void init_sockaddr (struct sockaddr_in *name, const char *hostname,int port)
{
struct hostent *hostinfo;
name->sin_family = AF_INET;
name->sin_port = htons (port);
hostinfo = gethostbyname (hostname);
#if ONEWAY
name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
#endif
#if ANOTHERWAY
bcopy(hostinfo->h_addr, (char*)&(name->sin_addr), hostinfo->h_length);
#endif
}
As I understand, there will be problems with the first way.
Because once the CPU leaves the function, hostinfo might be lost.
For now, it works, but I imagine it might one day fail.
My bigger concern is why it even compiles?
What is the "*" to the left of the "(" in that line?
What is it doing?
Admittedly, it was a mistake that worked, but I am more interested
in
- Next message: Magix: "Bitwise operation"
- Previous message: Emmanuel Delahaye: "Re: rank and expressions"
- Next in thread: Ravi Uday: "Re: Really odd pointer behavior"
- Reply: Ravi Uday: "Re: Really odd pointer behavior"
- Reply: Barry Margolin: "Re: Really odd pointer behavior"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|