C++ 在接受套接字连接时
如何解决此问题:-s为什么不使用此签名:C++ 在接受套接字连接时,c++,C++,如何解决此问题:-s为什么不使用此签名: unsigned __int8 Decrypt(unsigned __int8 data[]); for(;;) { if((sConnect=accept(sListen,(SOCKADDR*)&addr,&addrlen)) != INVALID_SOCKET) { Print("Socket Connected Successfully!");
unsigned __int8 Decrypt(unsigned __int8 data[]);
for(;;)
{
if((sConnect=accept(sListen,(SOCKADDR*)&addr,&addrlen)) != INVALID_SOCKET)
{
Print("Socket Connected Successfully!");
char buf[4095];
recv(sListen,buf,sizeof(buf),0);
Decrypt(buf); // Error:IntelliSense: argument of type "char *" is incompatible with parameter of type "unsigned char *"
}
而不是
unsigned char Decrypt(char *data);
如果这样做,您可以轻松地将
buf
传递给它,因为即使buf
声明为char-buf[4095]
,当您将其传递给Decrypt
时,它也会自动变为指针类型。不用投了 为什么不使用此签名:
unsigned __int8 Decrypt(unsigned __int8 data[]);
for(;;)
{
if((sConnect=accept(sListen,(SOCKADDR*)&addr,&addrlen)) != INVALID_SOCKET)
{
Print("Socket Connected Successfully!");
char buf[4095];
recv(sListen,buf,sizeof(buf),0);
Decrypt(buf); // Error:IntelliSense: argument of type "char *" is incompatible with parameter of type "unsigned char *"
}
而不是
unsigned char Decrypt(char *data);
如果这样做,您可以轻松地将
buf
传递给它,因为即使buf
声明为char-buf[4095]
,当您将其传递给Decrypt
时,它也会自动变为指针类型。不用投了 将其强制转换为正确的类型当调用Decrypt时,将其强制转换为正确的类型
unsigned __int8 Decrypt(unsigned __int8 data[]);
调用Decrypt时将buf强制转换为unsigned _int8
unsigned __int8 Decrypt(unsigned __int8 data[]);
为什么不将buf声明为type
unsigned\u int8[4095]
?@James(怪异):他可能会在recv()调用中遇到同样的编译器问题。@James(为什么我是怪异的一个?:P):那么就是C风格的强制转换了。为什么不将buf声明为typeunsigned\u int8[4095]
?@James(怪异):他可能会在recv()调用中遇到同样的编译器抱怨。@James(为什么我是那个奇怪的人?:P):那就是C风格的演员。