尝试将整数地址传递到要作为指针接收的函数时,出现编译器错误。这曾经是工作,但后来我在我的Makefile做了一些改变,现在它不再工作。我怀疑它的语法,但在这里它是:从不兼容的指针类型传递参数x ...
helper_funcs.h
void make_passive_connections(int *sockfd, Neighbor *neighbor, FILE *logfd, char this_router[64], struct sockaddr_in servAddr);
helper_funcs.c
void make_passive_connections(int *sockfd, Neighbor *neighbor, FILE *logfd, char this_router[64], struct sockaddr_in servAddr) {
...
}
在调用程序
int sockfd;
...
make_passive_connections(&sockfd, &neighbor, logfd, this_router->label, &servAddr, &num_hosts);
...
}
编译器还告诉我说我传递了太多争论。我的电脑有糟糕的一天,或者我忽略了什么?
这里是我的Makefile,如果有帮助:
CC = gcc
CFLAGS = -c -g -Wall -Wextra
SOURCES = fork.c helper_funcs.c primary.c
DEPS = primary.h fork.h helper_funcs.h
OBJECTS = $(SOURCES:.c=.o)
EXECUTABLE = primary
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) -o [email protected]
#.c.o:
# $(CC) $(CFLAGS) $< -o [email protected]
%.o: %.c $(DEPS)
$(CC) -c -o [email protected] $< $(CFLAGS)
clean:
rm -f *.o
rm -f $(EXECUTABLE)
警告:传递“make_passive_connections”的参数1从 兼容的指针类型
编辑:我是个白痴。我忘记删除我的函数调用中的最后一个参数。但我的主要问题是为什么编译器认为将整数地址传递给期望指向整数的函数不起作用。那有什么不对吗?
嗯,你是路过1个争论太多。你准确得到的错误是什么? – user2802841