2013-11-09 53 views
0

尝试将整数地址传递到要作为指针接收的函数时,出现编译器错误。这曾经是工作,但后来我在我的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

嗯,你是路过1个争论太多。你准确得到的错误是什么? – user2802841

回答

1

这是你的语法,我已经一字排开东西是不同的:

声明:

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); 

正如你所看到的,要传递六个参数,其中五个是预期。我和你的编译器一样糟糕。你也传递了一个结构的地址(我假设)在一个结构(通过值)预计。

+0

对不起,我粘贴了前面的代码行。你说得对。我仍然收到有关参数1上的不兼容指针类型的错误。我传递一个整数的地址,函数需要一个指向整数的指针。我没有看到任何问题。 – Alex

+0

@ usr55410:如果没有完整的可编译示例,则无法分辨。 –

0

原型:

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

呼吁少了一个参数(5),那么你已经通过(6):

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

,并在5日的说法是要求struct sockaddr_in,你是通过char *this_router->label

你的电话变更为:(删除最后一个参数,只有this_router通过)

make_passive_connections(&sockfd, &neighbor, logfd, this_router, &servAddr); 
相关问题