2015-06-07 112 views
1

这里的文件,我想使用包括: 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,但它让我看到警告..我应该把它定义(声明它) ?

+2

好吧,'setTitreMeta'没有在你发布的代码中的任何地方原型化,那么你还期望什么? – szczurcio

+0

这里我添加了bloc.c,但总是警告 – user3568611

回答

1

但我已经在bloc.c中定义了它。

你可能有定义它,但你也必须声明

声明说,bloc.h功能应该修复它。

+0

这里它的工作,当我在bloc.h中定义函数,当我在Bloc.c中这样做时,为什么它不工作? – user3568611

+0

因为声明函数和定义函数是有区别的。 在声明中,您基本上是说参数的返回类型和数量以及类型。例如: 'int foo(int,int);'< - 这在.h文件中。 在定义中你说的是函数的实际功能。例如: 'int foo(int a,int b){ int c; c = a + b; return c; }' 上面的代码在.c文件中。希望我已经清理了:) 对不起,格式不对,我是新来的。 – Frank

3

编译器不会说该函数没有定义。它说,该功能没有其使用前在文件primitives.c那里是它的呼叫

setTitreMeta(Nouv_Bloc.infosFic,nomfic); 

所以编译器无法说这个来电是否有效申报。

+0

,所以你的意思是我必须使用它?但是我在creat2函数中使用它 – user3568611

+0

它没问题:) – user3568611

+0

@ user3568611编译器需要查看函数声明来确定函数调用是否正确。 –

相关问题