Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试创建套接字,我应该描述一些结构:
(struct in_addr) addr; addr.s_addr = INADDR_ANY;
我也包括了标题
#include <sys/socket.h> #include <sys/types.h>
但是 gcc 说有一个错误:
error: ‘addr’ undeclared (first use in this function)
我究竟做错了什么?
要声明一个新in_addr结构,您需要删除这些括号:
in_addr
struct in_addr addr; addr.s_addr = INADDR_ANY;
您目前拥有的是一个演员表,这意味着(大约)“假设addr已经是某种其他类型的声明变量,请尝试将其转换为struct in_addr”。
addr
struct in_addr
把括号去掉。写吧
struct in_addr addr;