【发布时间】:2021-12-11 10:42:28
【问题描述】:
我正在尝试将在 linux 中开发的程序转换为 Visual Studio。该程序是C语言的。我尝试将 socket.h 中的套接字函数替换为 Visual Studio 中的套接字函数。这是我目前所拥有的。
#define _CRT_SECURE_NO_WARNINGS
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x6000
#endif
#undef UNICODE
#define UNICODE
#undef _WINSOCKAPI_
#define _WINSOCKAPI_
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#define _CRT_SECURE_NO_WARNINGS
struct the_socks
{
int sock_file_d;
struct sockaddr_in my_addr;
};
int main()
{
struct the_socks* my_sock;
int state = -1;
my_sock = (struct the_socks*)malloc(sizeof(struct the_socks));
struct sockaddr_in client_n, server_n;
if ((my_sock->sock_file_d = socket(AF_INET, SOCK_STREAM, 0)) >= 0)
{
state = 0;
}
}
即使代码非常相似,我在 linux 中也没有遇到错误。构建时出现以下错误:
Severity Code Description Project File Line Suppression State Detail Description
Warning C6011 Dereferencing NULL pointer 'my_sock'. Project3 C:\Users\stuff\source\main.c 33
如果有任何建议,我将不胜感激。
【问题讨论】:
标签: c sockets null-pointer