警告:隐式声明错误
warning : Implicit declaration error
这是文件,我想使用包括:
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
};
//别名
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;
我收到此警告:
primitives.c:8:2: attention : implicit declaration of function ‘setTitreMeta’ [-Wimplicit-function-declaration]
但是我已经在bloc.c中定义了它。
编辑: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);
}
我在 bloc.c 中定义它,但它向我显示警告.. 我应该在哪里定义它(声明它)?
编译器并没有说函数没有定义。它说该函数在调用
的文件primitives.c
中使用之前未声明
setTitreMeta(Nouv_Bloc.infosFic,nomfic);
所以编译器无法判断这个调用是否有效。
But i have defined it in bloc.c.
您可能已经定义了它,但您还必须声明它
在 bloc.h
中声明所述函数应该可以修复它。
这是文件,我想使用包括: 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
};
//别名 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;
我收到此警告:
primitives.c:8:2: attention : implicit declaration of function ‘setTitreMeta’ [-Wimplicit-function-declaration]
但是我已经在bloc.c中定义了它。
编辑: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);
}
我在 bloc.c 中定义它,但它向我显示警告.. 我应该在哪里定义它(声明它)?
编译器并没有说函数没有定义。它说该函数在调用
的文件primitives.c
中使用之前未声明
setTitreMeta(Nouv_Bloc.infosFic,nomfic);
所以编译器无法判断这个调用是否有效。
But i have defined it in bloc.c.
您可能已经定义了它,但您还必须声明它
在 bloc.h
中声明所述函数应该可以修复它。