wonjun
asked on
char* array
I have this code
char DataPacket[128];
SocketObject ClientSocketObject;
iBytesReceived = ClientSocketObject.Recv(&D ataPacket, 128, 0);
and, Recv is defined as,
int SocketObject::Recv( char *szBuffer, int iBufLen, int iFlags)
{
...
}
I'm using Visual Studio.Net 2005,
and when i compile,
i get this error
error C2664: 'SocketObject::Recv' : cannot convert parameter 1 from 'char (*__w64 )[128]' to 'char *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
However, this error goes away if i do,
iBytesReceived = ClientSocketObject.Recv(&D ataPacket[ 0], 128, 0); isntead of
iBytesReceived = ClientSocketObject.Recv(&D ataPacket, 128, 0);
and I was wondering if this is the correct way to solve the error. Any explnation will be appreciated. I belive this error does not occur in the old Visual C++ compilers.
Thank you very much
char DataPacket[128];
SocketObject ClientSocketObject;
iBytesReceived = ClientSocketObject.Recv(&D
and, Recv is defined as,
int SocketObject::Recv( char *szBuffer, int iBufLen, int iFlags)
{
...
}
I'm using Visual Studio.Net 2005,
and when i compile,
i get this error
error C2664: 'SocketObject::Recv' : cannot convert parameter 1 from 'char (*__w64 )[128]' to 'char *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
However, this error goes away if i do,
iBytesReceived = ClientSocketObject.Recv(&D
iBytesReceived = ClientSocketObject.Recv(&D
and I was wondering if this is the correct way to solve the error. Any explnation will be appreciated. I belive this error does not occur in the old Visual C++ compilers.
Thank you very much
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi!
Remove the & sign!
will result to this
iBytesReceived = ClientSocketObject.Recv(Da taPacket, 128, 0);
Patrik
Remove the & sign!
will result to this
iBytesReceived = ClientSocketObject.Recv(Da
Patrik
If you have an array...
char DataPacket[128];
then...
DataPacket[0] is a single char (the first one in the array)
&DataPacket[0] is a pointer to a char (char*)
(the same as.... )
DataPacket is a pointer to char (char*)
(however...)
&DataPacket is a pointer to that pointer (it's a char**)
The prototype requires a pointer-to-char, so either of these will work:
&DataPacket[0]
DataPacket