Problème d'inclusions multiples
Je pensais avoir compris comment protéger mon fichier d'entête, mais ce code ne fonctionne pas, et je ne vois pas pourquoi :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
/* main.c */
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include "second.h"
int main(int argc, char *argv[])
{
printf("mon texte : %s\n", texte) ;
system("PAUSE");
return 0;
} |
Code:
1 2 3 4 5 6 7
| /* main.h */
#ifndef H_MAIN_H
#define H_MAIN_H
const char *texte = "bla !" ;
#endif |
Code:
1 2 3 4 5 6
| /* second.c */
#include "second.h"
void ma_fonction(char *par) {
printf("mon texte : %s", par) ;
} |
Code:
1 2 3 4 5 6 7 8 9
| /* second.h */
#ifndef H_SECOND_H
#define H_SECOND_H
#include "main.h"
void ma_fonction(char *par) ;
#endif |
DEVCPP me renvoit un "multiple definition of 'texte'.
Ca marche très bien pour les prototypes de fonctions pourtant...