Problème appel de fonction avec structure en argument
Bonjour,
main.c :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include <stdio.h>
#include <stdlib.h>
#include "sub.h"
struct test
{
int x;
int y;
int *p;
};
int add(struct test *ts)
{
return ts->x + ts->y + (*ts->p);
}
int main(void)
{
struct test *ts;
ts = malloc(sizeof(*ts));
ts->x = 8;
ts->y = 2;
ts->p = &ts->y;
printf("%i\n", add(ts));
printf("%i\n", sub(ts));
return 0;
} |
sub.c :
Code:
1 2 3 4 5 6
| #include <stdio.h>
int sub(struct test *ts)
{
return ts->x - ts->y - (*ts->p);
} |
sub.h :
Code:
int sub(struct test *ts);
Me retourne avec gcc :
Citation:
In file included from main.c:3:
sub.h:1:16: warning: ‘struct test’ declared inside parameter list will not be visible outside of this definition or declaration
1 | int sub(struct test *ts);
| ^~~~
main.c: In function ‘main’:
main.c:27:21: warning: passing argument 1 of ‘sub’ from incompatible pointer type [-Wincompatible-pointer-types]
27 | printf("%i\n", sub(ts));
| ^~
| |
| struct test *
In file included from main.c:3:
sub.h:1:22: note: expected ‘struct test *’ but argument is of type ‘struct test *’
1 | int sub(struct test *ts);
| ~~~~~~~~~~~~~^~
sub.c:3:16: warning: ‘struct test’ declared inside parameter list will not be visible outside of this definition or declaration
3 | int sub(struct test *ts)
| ^~~~
sub.c: In function ‘sub’:
sub.c:5:11: error: dereferencing pointer to incomplete type ‘struct test’
5 | return ts->x - ts->y - (*ts->p);
| ^~