I have trouble understanding c header files and source files. I have:
something.c
#include <stdio.h>
#include "something.h"
typedef struct {
int row, col;
} point;
point
whereispoint(point **matrix, int rows, int cols)
{
..... Does something ....
printf("something...");
}
something.h
typedef struct point * p;
p whereispoint(p **matrix, int rows, int cols);
main.c
#include <stdio.h>
#include "something.h"
int
main(void)
{
int row, col;
p **matrix=malloc(bla, bla);
.....Something.....
p=whereispoint(matrix, row, col);
return 0;
}
Now when I don’t actually know how to compile this… I tried gcc -c main.c something.c
but that doesn’t work, I tried to compile separately gcc -c main.c and gcc -c something.c
then main.c works but something.c does not.
I am actually trying to make a library out of something.c but as I am not able even to compile it to object code I don’t know what to do. I guess there is something wrong with the struct type and the typedef of it in something.h but I can’t figure out what…
In the header, the function
whereispoint()is declare as returning astruct point*(thetypedef p) but the definition returns astruct point, not a pointer.Personally, I find
typedefpointers confusing and think it is clearer in the code if*is used to denote a pointer: