4
I have three files, produtos.h, produtos.c and main.c. produtos.h is located in the folder "headers", produtos.c is located in "sources" and main.c is in the same folder as "headers" and "sources", something like that:
pasta
\_headers
| \_produtos.h
\_sources
| \_produtos.c
\_main.c
main. c:
#include <stdio.h>
#include <stdlib.h>
#include "headers/produtos.h"
int main(int argc, char** argv){
struct produto p;
p.id = 123;
printf("Id: %d\n", p.id);
return 0;
}
products. h:
#ifndef PRODUTOS_H
#define PRODUTOS_H
struct produto;
#endif
products. c:
#include "../headers/produtos.h"
struct produto {
char nome[100];
};
When compiling, I get the following error message:
main.c: In function 'main': main.c:6:20: error: storage size of 'p' isn't known struct produto p; ^
As my tests indicate, the compiler cannot receive the implementation of struct product, that is, it cannot receive produtos.c, only produtos.h, what my mistake?
This solves, yes, but the problem will continue if instead of me declaring a struct, I declare a function. I can’t put the entire implementation of a function in my header.
– Vinicius Castro
But you put the function header in the header... no?
– Woss
Implementation does not need to be included, so no problem.
– Maniero