c - 从不兼容的指针类型传递参数 x ...

标签 c makefile

当我尝试将整数的地址传递给要作为指针接收的函数时,出现编译器错误。这曾经是有效的,但后来我对我的 Makefile 做了一些更改,现在它不再有效了。我怀疑这是否是语法,但它是:

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 $@

#.c.o:
#   $(CC) $(CFLAGS) $< -o $@

%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

clean:
    rm -f *.o
    rm -f $(EXECUTABLE)

warning: passing argument 1 of ‘make_passive_connections’ from incompatible pointer type

编辑:我是个白痴。我忘记删除函数调用中的最后一个参数。但我的主要问题是为什么编译器认为将整数的地址传递给需要指向整数的指针的函数不起作用。这有什么问题吗?

最佳答案

这是你的语法,我以不同的方式排列了内容:

声明:

void make_passive_connections(int *sockfd,    Neighbor *neighbor,
                              FILE *logfd,    char this_router[64],
                              struct sockaddr_in servAddr);

通话

make_passive_connections(     &sockfd,        &neighbor,
                              logfd,          this_router->label,
                              &servAddr,      &num_hosts);

正如您所看到的,您传递了六个参数,而预期为五个参数。我的日子和你的编译器一样糟糕。您还传递了一个结构体的地址(我假设),其中需要一个结构体(按值)。

关于c - 从不兼容的指针类型传递参数 x ...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19883848/

相关文章:

c++ - 多个目标的Makefile优化

go - 使用 make 为不同的体系结构构建动态目标?

c - 非常基本的 makefile linux

c - 将大量字符串发送到标准输出的最佳方法是什么?

c - 如何使用 extern 从 C 调用带有签名 std::list 的 C++ 方法?

c - 为什么递归函数的输出为0?

c - 尝试重新排序链表时 free() 无效

c - C 中带负 float 的断言

c++ - GoogleTest CMake 和 Make 测试未运行

java - bash 脚本问题启动程序