1

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 )?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
user3568611
  • 133
  • 2
  • 14

2 Answers2

3

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
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.

Frank
  • 250
  • 3
  • 10
  • Here it work , when i define the function in bloc.h, why it doesnt work when I do that in Bloc.c ? – user3568611 Jun 07 '15 at 10:21
  • Because there is a difference in declaring a function vs defining one. In the declaration you are basically saying the return type and number and types of the arguments. For example: `int foo( int , int );` <- This goes in the .h file. In the definition you are saying what the function actually does. For example: `int foo(int a, int b){ int c; c=a+b; return c; }` The code above goes in the .c file. Hope I've cleared it up :) Sorry for bad formatting, I'm new here. – Frank Jun 07 '15 at 16:00