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 :

Structures, erreurs de compilation


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    182
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 182
    Par défaut Structures, erreurs de compilation
    J'ai developpé un programme en C sous visual studio.... A la compilation je n'ai aucune erreur et le programme fonctionne parfaitement.

    Celui-ci est destine a tourner sous UNIX mais lorsque j'essaye de le compiler avec cc sous UNIX il m'indique une erreur de syntaxe dans le .h contenant mes strutures.

    Lorsque j'essaye de compiler mon source sous cygwin en lui laissant l'extension .cpp (par defaut sous VS) la compilation est ok. Mais si je le renomme en .c la ca ne fonctionne plus, il me met plusieurs pages d'erreurs, la majeure partie en relation avec ma structure. J'ai potassé mes cours de C car ca fait longtemps que je n'en ai pas fait mais c'est bien la méthode que l'on m'a apprise que j'ai appliqué... mais lors des cours on compilait avec VS donc......

    Une de mes structures de mon .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
     
     
    struct FACT
    {
    	int numFact;
    	int closedTime;
    	int numPdsFact;
    	char * namePdsFact;
    	int numRvc;
    	char * nameRvc;
    	int miNumber;
    	int miMajNum;
    	char * miMajName;
    	int dscNum;
    	char * dscName;
    	int nbCover;
    	float montant;
    	float montantDsc;
    	int flag;
    	FACT * lineSuiv;
    };
    Ensuite, au dessus de mon main() je declare un pointeur vers ma structure :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    FACT * pdebF = NULL;		   // Debut du chainage
    Et j'accède aux elements de ma structure par pdebF->flag

    Ou est l'erreur ???
    Sous cygwin mes structures ne sont pas reconnues et chaque fois que je les utilise il me met un message d'erreur. Je précise que j'ai bien ajouté un #include de mon .h entre guillemets avant mon main et que mon .h est bien present dans le repertoire du source.


    Merci d'avance.

  2. #2
    Expert confirmé

    Avatar de fearyourself
    Homme Profil pro
    Ingénieur Informaticien Senior
    Inscrit en
    Décembre 2005
    Messages
    5 121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur Informaticien Senior
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2005
    Messages : 5 121
    Par défaut
    Il faudrait un code complet, minimal qui expose le problème. Comme ca, on ne va pas pouvoir dire grand chose...

    Jc

  3. #3
    Membre Expert
    Avatar de muad'dib
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2003
    Messages
    1 013
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2003
    Messages : 1 013
    Par défaut
    Quel est le message d'erreur? Est ce que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    struct FACT
    {
    	int numFact;
            .....
    	struct FACT * lineSuiv;
    };
    n'aide pas?

  4. #4
    Membre émérite Avatar de crocodilex
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    697
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 697
    Par défaut
    J'espère que tu n'as pas oublié un typedef juste avant la définition de ta structure :
    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
    typedef struct FACT FACT;
     
    struct FACT
    {
    	int numFact;
    	int closedTime;
    	int numPdsFact;
    	char * namePdsFact;
    	int numRvc;
    	char * nameRvc;
    	int miNumber;
    	int miMajNum;
    	char * miMajName;
    	int dscNum;
    	char * dscName;
    	int nbCover;
    	float montant;
    	float montantDsc;
    	int flag;
    	FACT * lineSuiv;
    };

  5. #5
    Expert confirmé

    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    10 610
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 10 610
    Billets dans le blog
    2
    Par défaut
    Moi je préfère toujours mettre dans la même instruction la définition de la structure et du pointeur, pour ne pas faire ce genre d'oubli :


    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
     
    typedef struct PFACT
    {
    	int numFact;
    	int closedTime;
    	int numPdsFact;
    	char * namePdsFact;
    	int numRvc;
    	char * nameRvc;
    	int miNumber;
    	int miMajNum;
    	char * miMajName;
    	int dscNum;
    	char * dscName;
    	int nbCover;
    	float montant;
    	float montantDsc;
    	int flag;
    	struct PFACT * lineSuiv;
    } FACT;

  6. #6
    Membre éprouvé Avatar de psyphi
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    119
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Allemagne

    Informations professionnelles :
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2006
    Messages : 119
    Par défaut
    @Souviron: Je ne sais pas si les typedef sur les structures est ce qui ce fait de mieu.

    Extrait chapitre 5 CodingStyle noyeau linux:
    Merci de ne pas utiliser de choses comme "vps_t"
    C'est une erreur d'utiliser des typedef pour des strutures et pointeurs.
    Quand vous voyez cela dans une source quelle est sa signification.
    A contrario en écrivant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    struct virtual_container *a;
    on peut directement voir ce qu'est a.
    ...
    Bon c'est juste un conseil de style de code, a débattre...

  7. #7
    Expert confirmé

    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    10 610
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 10 610
    Billets dans le blog
    2
    Par défaut
    bah, C99 dit :

    6.7.2.3 Tags
    Constraints

    1 A specific type shall have its content defined at most once.
    2 A type specifier of the form enum identifier without an enumerator list shall only appear after the type it specifies is complete.
    Semantics
    3 All declarations of structure, union, or enumerated types that have the same scope and use the same tag declare the same type. The type is incomplete109) until the closing brace of the list defining the content, and complete thereafter.
    4 Two declarations of structure, union, or enumerated types which are in different scopes or use different tags declare distinct types. Each declaration of a structure, union, or enumerated type which does not include a tag declares a distinct type.
    5 A type specifier of the form
    struct-or-union identifieropt { struct-declaration-list }
    or
    enum identifier { enumerator-list }
    or
    enum identifier { enumerator-list , }
    declares a structure, union, or enumerated type. The list defines the structure content, union content, or enumeration content. If an identifier is provided,110) the type specifier also declares the identifier to be the tag of that type.

    109) An incomplete type may only by used when the size of an object of that type is not needed. It is not needed, for example, when a typedef name is declared to be a specifier for a structure or union, or when a pointer to or a function returning a structure or union is being declared. (See incomplete types in 6.2.5.) The specification has to be complete before such a function is called or defined.

    6 A declaration of the form
    struct-or-union identifier ;
    specifies a structure or union type and declares the identifier as a tag of that type.111)
    7 If a type specifier of the form
    struct-or-union identifier
    occurs other than as part of one of the above forms, and no other declaration of the identifier as a tag is visible, then it declares an incomplete structure or union type, and declares the identifier as the tag of that type.

    111) A similar construction with enum does not exist.

    8 If a type specifier of the form
    struct-or-union identifier
    or
    enum identifier
    occurs other than as part of one of the above forms, and a declaration of the identifier as a tag is visible, then it specifies the same type as that other declaration, and does not redeclare the tag.
    9 EXAMPLE 1 This mechanism allows declaration of a self-referential structure.
    struct tnode {
    int count;
    struct tnode *left, *right;
    };
    specifies a structure that contains an integer and two pointers to objects of the same type. Once this declaration has been given, the declaration
    struct tnode s, *sp;
    declares s to be an object of the given type and sp to be a pointer to an object of the given type. With these declarations, the expression sp->left refers to the left struct tnode pointer of the object to which sp points; the expression s.right->count designates the count member of the right struct
    tnode pointed to from s.

    110) If there is no identifier, the type can, within the translation unit, only be referred to by the declaration
    of which it is a part. Of course, when the declaration is of a typedef name, subsequent declarations
    can make use of that typedef name to declare objects having the specified structure, union, or
    enumerated type.
    111) A similar construction with enum does not exist.

    10 The following alternative formulation uses the typedef mechanism:
    typedef struct tnode TNODE;
    struct tnode {
    int count;
    TNODE *left, *right;
    };
    TNODE s, *sp;

    11 EXAMPLE 2 To illustrate the use of prior declaration of a tag to specify a pair of mutually referential structures, the declarations
    struct s1 { struct s2 *s2p; /* ... */ }; // D1
    struct s2 { struct s1 *s1p; /* ... */ }; // D2
    specify a pair of structures that contain pointers to each other. Note, however, that if s2 were already declared as a tag in an enclosing scope, the declaration D1 would refer to it, not to the tag s2 declared in D2. To eliminate this context sensitivity, the declaration struct s2;
    may be inserted ahead of D1. This declares a new tag s2 in the inner scope; the declaration D2 then completes the specification of the new type.
    Et quant à moi je préfère voir en même temps le tag et le nom de la structure.. sans compter l'économie de clavier

  8. #8
    Expert confirmé
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Par défaut
    Préfixe FACT par struct
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    struct FACT
    {
    ...
    struct FACT * lineSuiv;
    };
    ...
    struct FACT * pdebF = NULL;

Discussions similaires

  1. Erreur de compilation avec une structure
    Par existenz3 dans le forum Débuter
    Réponses: 3
    Dernier message: 10/12/2010, 09h07
  2. erreur de compilation : probleme avec type de structure dans une classe
    Par medkarim dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 21/10/2008, 15h33
  3. Erreur de compilation après modification du Uses
    Par DevelOpeR13 dans le forum Langage
    Réponses: 5
    Dernier message: 30/10/2007, 14h23
  4. Réponses: 4
    Dernier message: 27/08/2003, 21h34
  5. Réponses: 2
    Dernier message: 04/03/2003, 23h24

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