IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Probleme d'inclusions


Sujet :

C

  1. #1
    Membre averti Avatar de Trillian
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    47
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 47
    Par défaut Probleme d'inclusions
    J'ai le probleme suivant:

    2 modules s'incluant mutuellement, cad:

    TabPixel.h : #include "ContourDiscret.h"
    TabPixel.c : #include "TabPixel.h"
    ContourDiscret..h : #include "TabPixel.h"
    ContourDiscret.c : #include "ContourDiscret.h"

    et j'arrive pas a compiler:
    gcc -g -Wall -DPOSIX_C_SOURCE=1 -I../..//include -c -o TabPixel.o TabPixel.c
    In file included from TabPixel.h:5,
    from TabPixel.c:16:
    ContourDiscret.h:30: error: parse error before "tabPixel"
    ContourDiscret.h:32: error: parse error before "getCanal"
    ContourDiscret.h:32: error: parse error before "t"


    Voici les lignes30 et 32 donc:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    #30> extern int appartient(int x, int y, int *contour, tabPixel t);
    #31>
    #32> extern tabPixel getCanal(tabPixel t, contourDiscret c);
    gcc -g -Wall -DPOSIX_C_SOURCE=1 -I../..//include -c -o ContourDiscret.o ContourDiscret.c
    In file included from ContourDiscret.h:4,
    from ContourDiscret.c:11:
    TabPixel.h:44: error: parse error before "contourDiscret"


    La ligne 44:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    #44> extern tabPixel getContenu(tabPixel t, char *etiquette, contourDiscret c);

  2. #2
    Expert confirmé
    Avatar de PRomu@ld
    Homme Profil pro
    Ingénieur de Recherche
    Inscrit en
    Avril 2005
    Messages
    4 155
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Ingénieur de Recherche
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 4 155
    Par défaut
    Depuis quand met-on extern des prototypes de fonctions ?

    IL me semble (mais je ne suis pas un expert) mais extern devrait être utilisé uniquement pour des variables.

    TabPixel.h : #include "ContourDiscret.h"
    TabPixel.c : #include "TabPixel.h"
    ContourDiscret..h : #include "TabPixel.h"
    ContourDiscret.c : #include "ContourDiscret.h"
    En théorie, si tu utilises les directives #ifndef , #define, #endif ça ne devrait pas poser de problème.

  3. #3
    Membre averti Avatar de Trillian
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    47
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 47
    Par défaut
    Citation Envoyé par PRomu@ld
    Depuis quand met-on extern des prototypes de fonctions ?

    IL me semble (mais je ne suis pas un expert) mais extern devrait être utilisé uniquement pour des variables.
    Je sais pas, mais mon prof en utilise...

    pnm.h:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
     
    /* PNM: loading and saving pbm/pgm/ppm files
     * Copyright (C) 1996, 99, 2003 Achille Braquelaire :) (achille@labri.fr)
     * 
     * This file is part of BCL (Basic Library for C programs)
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU Library General Public
     * License as published by the Free Software Foundation (Inc., 59
     * Temple Place - Suite 330, Boston, MA 02111-1307, USA); either
     * version 2 of the License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * Library General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
     */
     
    #ifndef PNM_H
    #define PNM_H
     
    #define PNM_OFFSET(WIDTH,LINE,COLUMN) (3*((LINE)*(WIDTH) + (COLUMN)))
     
    typedef enum
    { 
        PnmRed = 0,
        PnmGreen = 1,
        PnmBlue = 2
    } pnmChannel;
     
    typedef enum
    {
        PnmAsciiPbm = 0,
        PnmAsciiPgm = 1,
        PnmAsciiPpm = 2,
        PnmRawPbm = 3,
        PnmRawPgm = 4,
        PnmRawPpm = 5,
        PnmAscii = 6, 
        PnmRaw = 7
    } pnmType;
     
    typedef struct pnm *pnm;
     
    extern pnm pnm_new(int width, int height, pnmType type);
    extern void pnm_free(pnm self);
     
    extern pnm pnm_init(pnm self);
    extern pnm pnm_dup(pnm self);
     
    extern pnm pnm_load(char *path);
    extern void pnm_save(pnm self, pnmType type, char *path);
     
     
    extern pnmType pnm_get_type(pnm self);
    extern int pnm_get_width(pnm self);
    extern int pnm_get_height(pnm self);
     
    extern unsigned char *pnm_make_uchar_rgb_image(pnm self, unsigned char *buffer);
    extern void pnm_set_uchar_rgb_image(pnm self, unsigned char *buffer);
     
    extern unsigned short *pnm_get_channel(pnm self, unsigned short *buffer, pnmChannel channel);
    extern void pnm_set_channel(pnm self, unsigned short *buffer, pnmChannel channel);
     
    extern unsigned short *pnm_get_image(pnm self);
    extern int pnm_offset(pnm self, int line, int column);
     
    extern unsigned short pnm_get_component(pnm self, int i, int j, pnmChannel channel);
    extern void pnm_set_component(pnm self, int i, int j, pnmChannel channel, unsigned short v);
     
    extern unsigned short pnm_maxval;
     
    #endif  /* PNM_H */
    pnm.c
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
     
    /* PNM: loading and saving pbm/pgm/ppm files
     * Copyright (C) 1996, 99, 2003 Achille Braquelaire :) (achille@labri.fr)
     * 
     * This file is part of BCL (Basic Library for C programs)
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU Library General Public
     * License as published by the Free Software Foundation (Inc., 59
     * Temple Place - Suite 330, Boston, MA 02111-1307, USA); either
     * version 2 of the License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * Library General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
     */
     
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
     
    #include <bcl.h>
     
    #include "pnm.h"
     
    ...
     
    pnm
    pnm_load(char *path)
    {
        FILE *input = L_r_open(path);
        pnm self = NULL;
     
        HANDLE(any, self = L_load(input));
        fclose(input);
     
        if (EXCEPTION_RAISED(any))
        {
    	if (self != NULL)
    	    memory_free(self);
     
    	if (EXCEPTION_RAISED(get_int))
    	    RAISE(error, "Truncated pnm file");
     
    	if (EXCEPTION_RAISED(any))
    	    RAISE_AGAIN();
        }
        return self;
    }
     
    pnm
    pnm_init(pnm self)
    {
        return L_init(self->width, self->height, self->original_type);
    }
     
    pnm
    pnm_dup(pnm self)
    {
        pnm result = pnm_init(self);
     
        memcpy(result->image, 
    	   self->image, 
    	   3*self->width*self->height*sizeof(unsigned short));
     
        return result;
    }
    ...

    J'ai teste en eliminant les extern, mais ca marche toujours pas.

    Citation Envoyé par PRomu@ld
    En théorie, si tu utilises les directives #ifndef , #define, #endif ça ne devrait pas poser de problème.
    Oui, toujours... mais ca marche pas quand meme.

  4. #4
    Expert éminent
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 68
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Par défaut
    Citation Envoyé par PRomu@ld
    Depuis quand met-on extern des prototypes de fonctions ?
    Depuis toujours.
    • C'est techniquement faisable
    • Ca ne change rien sur le plan sémantique
    • Ca a une valeur documentaire non négligeable.

    Personnellement, je ne l'utilisae pas pour les prototypes de fonction. Mais je comprends qu'on le fasse.

  5. #5
    Expert confirmé
    Avatar de PRomu@ld
    Homme Profil pro
    Ingénieur de Recherche
    Inscrit en
    Avril 2005
    Messages
    4 155
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Ingénieur de Recherche
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 4 155
    Par défaut
    C'est techniquement faisable
    Ca ne change ie sur le plan sémantique
    Ok d'accord, si ça ne change rien, je comprend pourquoi je ne l'utilise pas.

    Ca a une valeur documentaire non négligeable.
    Oui, sans doute, mais un commentaire même succint peut tout aussi bien servir...

    Personnellement, je ne l'utilisae pas pour les prototypes de fonction. Mais je comprends qu'on le fasse.
    On est donc du même avis.

  6. #6
    Membre averti Avatar de Trillian
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    47
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 47
    Par défaut
    Moi non plus je l'utilisais pas, mais j'ai pris exemple sur Maitre Achille

  7. #7
    Membre averti Avatar de Trillian
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    47
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 47
    Par défaut Resolu
    Pour ceux que cela interesse, le probleme est resolu. Il fallait tout simplement mettre les

    typedef struct machin *machin;

    au dessus des #include... 8)

    Merci Maitre Achille !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Probleme d'inclusion d'un container d'une classe dans une autre
    Par Tavarez59 dans le forum Interfaces Graphiques en Java
    Réponses: 1
    Dernier message: 30/03/2007, 22h41
  2. probleme d'inclusion multiple
    Par chrono23 dans le forum C++
    Réponses: 3
    Dernier message: 02/11/2006, 10h30
  3. probleme d'inclusions multiple
    Par porco dans le forum C++
    Réponses: 4
    Dernier message: 10/10/2006, 10h08
  4. Problème d'inclusion de code Assembleur dans du C
    Par tnarol dans le forum x86 32-bits / 64-bits
    Réponses: 5
    Dernier message: 06/09/2006, 18h56
  5. probleme d'inclusion
    Par porcher dans le forum C++
    Réponses: 5
    Dernier message: 03/03/2005, 20h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo