У меня есть это в моей основной функции:
Data* countries_tail = NULL;
Data* countries_head = NULL;
readFile(countries_f, &countries_head, &countries_tail, &size, 0);
Это объявление readFile:
void readFile(FILE* f, void** head, void** tail, int* size, int city);
В первой строке readFile я вызываю функцию, которая бросает voidуказатели на правильный тип.
castHeadTail(&head, &tail, city);
Это функция:
void castHeadTail(void*** head, void*** tail, int city){
if (city){
*head = (Cities**) (*head);
*tail = (Cities**) (*tail);
}
else{
*head = (Data**) (*head);
*tail = (Data**) (*tail);
}
}
Внутри readFile Я также делаю это:
if (city)
readCities(head, tail, line);
else
readCountries(head, tail, line, size);
Это объявления дляэти функции:
void readCities(Cities** head, Cities** tail, char* line);
void readCountries(Data** head, Data** tail, char* line, int* size);
Кажется, что все работает правильно, и valgrind говорит, что нет ошибок памяти.Тем не менее, я получаю много предупреждений при компиляции своего кода.Вот все предупреждения:
process.c: In function ‘readFile’:
process.c:96:17: warning: passing argument 1 of ‘readCities’ from incompatible pointer type [enabled by default]
readCities(head, tail, line);
^
In file included from process.c:3:0:
process.h:105:6: note: expected ‘struct Cities **’ but argument is of type ‘void **’
void readCities(Cities** head, Cities** tail, char* line);
^
process.c:96:17: warning: passing argument 2 of ‘readCities’ from incompatible pointer type [enabled by default]
readCities(head, tail, line);
^
In file included from process.c:3:0:
process.h:105:6: note: expected ‘struct Cities **’ but argument is of type ‘void **’
void readCities(Cities** head, Cities** tail, char* line);
^
process.c:98:17: warning: passing argument 1 of ‘readCountries’ from incompatible pointer type [enabled by default]
readCountries(head, tail, line, size);
^
In file included from process.c:3:0:
process.h:91:6: note: expected ‘struct Data **’ but argument is of type ‘void **’
void readCountries(Data** head, Data** tail, char* line, int* size);
^
process.c:98:17: warning: passing argument 2 of ‘readCountries’ from incompatible pointer type [enabled by default]
readCountries(head, tail, line, size);
^
In file included from process.c:3:0:
process.h:91:6: note: expected ‘struct Data **’ but argument is of type ‘void **’
void readCountries(Data** head, Data** tail, char* line, int* size);
^
process.c: In function ‘castHeadTail’:
process.c:199:15: warning: assignment from incompatible pointer type [enabled by default]
*head = (Cities**) (*head);
^
process.c:200:15: warning: assignment from incompatible pointer type [enabled by default]
*tail = (Cities**) (*tail);
^
process.c:203:15: warning: assignment from incompatible pointer type [enabled by default]
*head = (Data**) (*head);
^
process.c:204:15: warning: assignment from incompatible pointer type [enabled by default]
*tail = (Data**) (*tail);
Я не уверен, что делать, чтобы исправить эти предупреждения, я не привык использовать общие указатели и, поскольку программа, кажется, работает правильно, я буквально понятия не имею,почему они там.
Кроме того, извините за то, что не включили полный и компилируемый пример, демонстрирующий проблему, я не был уверен, как показать проблему, когда, кажется, нет проблемы с кодом.