问题
Here's the files , i want to use includes : primitives.h:
#ifndef PRIMITIVES_H_
#define PRIMITIVES_H_
#include "bloc.h"
#endif
primitives.c
#include "primitives.h"
Bloc_T creat2(char* ,BT_T);
Bloc_T creat2(char* nomfic ,BT_T typefic)
{
Bloc_T Nouv_Bloc;
setTitreMeta(Nouv_Bloc.infosFic,nomfic);
Nouv_Bloc.typeBloc= typefic;
return Nouv_Bloc;
}
bloc.h:
#ifndef STRUCTURES_H_INCLUDED
#define STRUCTURES_H_INCLUDED
// BIBLIOTHEQUES STANDARDS
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
// MACROS
#define TAILLE_BD 20
#define NBR_BLOC_PAR_FIC 5
struct Metadonnees
{
char* nomFic;
};
// Alias
typedef struct Metadonnees MD_T;
enum blocType{
BV,BD,BREP,BI
};
// Alias typedef enum blocType BT_T;
struct Bloc
{
BT_T typeBloc;
int** adressesInodes; //tableau des adresses des BD (BI ou BRep)
MD_T infosFic;
char* data; //bloc données
char** nomsFic; // pour les BRep
// bloc vide: tout à null
};
// Alias
typedef struct Bloc Bloc_T;
I get this warning:
primitives.c:8:2: attention : implicit declaration of function ‘setTitreMeta’ [-Wimplicit-function-declaration]
But i have defined it in bloc.c.
Edit: Bloc.c #include "bloc.h"
void setTitreMeta(MD_T , char* );
void setTitreMeta(MD_T meta, char* titre)
{
int taille = strlen(titre);
meta.nomFic=(char*)malloc(sizeof(char)*taille);
strcpy(meta.nomFic,titre);
printf("Nom du fichier: %s\n",meta.nomFic);
}
I'm defining it in bloc.c but it shows me the warning .. where should I define it ( declare it )?
回答1:
But i have defined it in bloc.c.
You may have defined it, but you also have to declare it
Declaring said function in bloc.h
should fix it.
回答2:
The compiler does not say that the function is not defined. It says that the function is not declared before its usage in file primitives.c
where there is its call
setTitreMeta(Nouv_Bloc.infosFic,nomfic);
So the compiler is unable to say whether this call is valid.
来源:https://stackoverflow.com/questions/30692183/warning-implicit-declaration-error