小编use*_*872的帖子

你能在另一个文件中使用#define变量吗?

例如,abc.c包含一个变量

#define NAME "supreeth"
Run Code Online (Sandbox Code Playgroud)

可以NAMEdef.c替换变量吗?

c global extern

12
推荐指数
3
解决办法
3万
查看次数

"'sockaddr_in'未声明(在此函数中首次使用)"错误,尽管包含必需的标题

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <stdlib.h>
#include <memory.h>
#include <ifaddrs.h>#include <net/if.h>
#include <stdarg.h>

#define BACKLOG 10

void * get_in_addr(struct sockaddr *sa){
    if(sa->sa_family == AF_INET){
            return &((sockaddr_in *)sa)->sin_addr;
    }
    else if(sa->sa_family == AF_INET6){
            return &((sockaddr_in6 *)sa)->sin6_addr;
    }
}
Run Code Online (Sandbox Code Playgroud)

我在我的代码中使用sockaddr_in结构来判断传入连接是IPv4还是IPV6地址.尽管在我的代码中包含netinet/in.h头文件,但我收到错误"'sockaddr_in'未声明(在此函数中首次使用)".有没有我在这里看不到的东西?

c sockets header-files

5
推荐指数
1
解决办法
5550
查看次数

标签 统计

c ×2

extern ×1

global ×1

header-files ×1

sockets ×1