Я пытаюсь использовать мою структуру peer_struct.h в нескольких файлах.Он объявлен в main.c, и я передаю ссылку на структуру через.
Компилятор дает мне предупреждения для функций, и я действительно не понимаю, почему.
Предупреждения компилятора:
In file included from first_use.c:1:0:
second_use.h:1:51: warning: ‘struct Peer_Information’ declared inside parameter list will not be visible outside of this definition or declaration
void second_use(char *message, int number, struct Peer_Information *peer);
^~~~~~~~~~~~~~~~
first_use.c: In function ‘first_use’:
first_use.c:6:23: warning: passing argument 3 of ‘second_use’ from incompatible pointer type [-Wincompatible-pointer-types]
second_use(me, 5, peer);
^~~~
In file included from first_use.c:1:0:
second_use.h:1:6: note: expected ‘struct Peer_Information *’ but argument is of type ‘struct Peer_Information *’
void second_use(char *message, int number, struct Peer_Information *peer);
^~~~~~~~~~
In file included from main.c:4:0:
first_use.h:1:23: warning: ‘struct Peer_Information’ declared inside parameter list will not be visible outside of this definition or declaration
void first_use(struct Peer_Information *peer);
^~~~~~~~~~~~~~~~
main.c: In function ‘main’:
main.c:28:15: warning: passing argument 1 of ‘first_use’ from incompatible pointer type [-Wincompatible-pointer-types]
first_use(&peer);
^
In file included from main.c:4:0:
first_use.h:1:6: note: expected ‘struct Peer_Information *’ but argument is of type ‘struct Peer_Information *’
void first_use(struct Peer_Information *peer);
peer_struct.h
struct Peer_Information {
char ownIP[16];
char ownPort[6];
unsigned int ownID;
char successor_IP[16];
char successor_Port[6];
unsigned int successor_ID;
char predecessor_IP[16];
char predecessor_Port[6];
unsigned int predecessor_ID;
} Peer_Information;
main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "first_use.h"
#include "peer_struct.h"
void init_peer(char *argv[], struct Peer_Information *peer){
//Fills struct up, not import for question
}
int main(int argc, char *argv[]) {
if (argc != 10) {
printf("Nicht genügend Parameter \n");
return -1;
}
struct Peer_Information peer;
init_peer(argv, &peer);
first_use(&peer);
return 0;
}
first_use.c
#include "second_use.h"
#include "peer_struct.h"
void first_use(struct Peer_Information *peer) {
char me[] = "Hello";
second_use(me, 5, peer);
}
first_use.h
void first_use(struct Peer_Information *peer);
second_use.c
#include <stdio.h>
#include <stdlib.h>
#include "peer_struct.h"
void second_use(char *message, int number, struct Peer_Information *peer) {
printf("%d", peer->ownID);
}
second_use.h
void second_use(char *message, int number, struct Peer_Information *peer);