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'initialisation de structure avec une macro


Sujet :

C

  1. #1
    Membre averti Avatar de Fooshi
    Homme Profil pro
    ICD
    Inscrit en
    Juin 2002
    Messages
    507
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : ICD
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 507
    Points : 359
    Points
    359
    Par défaut Probleme d'initialisation de structure avec une macro
    Bonjour,
    j'ai un problème d'initialisation de structure avec une macro, j'ai une macro block_list_init_head qui initialise ma structure block_list_head :

    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
     
    // The block list header structure
    struct block_list_head
    {
    	struct linked_list_head	head;	///< Block list head are linked list head       
    	struct block_pool *		pool;	///< A pointer to the Block Pool
    	unsigned int			free;	///< Free size int he Block Pool
    };
     
    /// Initialise a block list head
    /**
      * \param head A pointer to the head of a list.
      * \param pool A pointer to the block pool
      */
    #define block_list_init_head(head,pool) linked_list_init_head((struct block_list_head *)(head)); ((struct block_list_head *)(head))->pool = pool; ((struct block_list_head *)(head))->free = 0
    ensuite je retourne un pointeur sur head.pool qui est un pointeur sur une structure de type block_pool et j'initialise ma structure head avec la macro.
    mais le compilateur me dis que pool n'est pas un membre de 'linked_list_head' mais dans ma macro je lui dis bien que pool est un membre de 'block_list_head' donc je ne comprend pas l'erreur.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    static struct block_list_head head;
     
    head.pool = block_pool_create(sizeof(struct block_list_head),sizeof(struct block_list_head)* 32,1,0);
    block_list_init_head(&head,head.pool);			// Initialize the linked list of block pool
    quel pourrais etre l'erreur dans mon code ? merci d'avance car la je bloque pas mal.

    erreur du compilo :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    2>d:\svn\age\tests\blocklist\blocklist.c(22) : error C2039: 'pool' : is not a member of 'linked_list_head'
    2>        d:\svn\age\common\include\linked_list.h(33) : see declaration of 'linked_list_head'

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    1 298
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 1 298
    Points : 886
    Points
    886
    Par défaut
    Salut, je ne vais pas répondre à ta question mais j'ai un commentaire à faire sur ta macro :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    #define block_list_init_head(head,pool) linked_list_init_head((struct block_list_head *)(head)); ((struct block_list_head *)(head))->pool = pool; ((struct block_list_head *)(head))->free = 0
    Le problème est que si tu fais un truc du genre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    if(condition)
      block_list_init_head(head,pool)
    comme tu n'as pas mis d'accolades, seule la 1e instruction de ta macro sera prise en compte... Je te conseille de faire ceci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    #define block_list_init_head(head,pool) \
    do { \
    linked_list_init_head((struct block_list_head *)(head)); \
    ((struct block_list_head *)(head))->pool = pool;\
    ((struct block_list_head *)(head))->free = 0;\
    }\
    while(0)
    et ensuite tu pourras faire en toute sécurité :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    if(condition)
      block_list_init_head(head,pool);

  3. #3
    Membre averti Avatar de Fooshi
    Homme Profil pro
    ICD
    Inscrit en
    Juin 2002
    Messages
    507
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : ICD
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 507
    Points : 359
    Points
    359
    Par défaut
    meme si tu ne repond pas a ma question merci quand meme j'ai modifié mon code en consequence. je n'utilise pas de condition avant mes macros mais plus tard on sais jamais !

    concernant mon erreur je rajoute ma macro 'linked_list_init_head' qui est appelée dans la macro 'block_list_init_head'

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    #define linked_list_init_head(head)	((struct linked_list_head *)(head))->first = NULL; ((struct linked_list_head *)(head))->last = NULL
    et la structure en question 'linked_list_head'


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    /// The linked list head structure.
    struct linked_list_head
    {
    	struct linked_list_elem * first; ///< A pointer to the first element in the list.
    	struct linked_list_elem * last;  ///< A pointer to the last element in the list.
    };
    mon probleme viendrais pas d'un probleme de macro imbriquées par hasard ? (je debute vraiment dans les macros)

  4. #4
    Membre averti Avatar de Fooshi
    Homme Profil pro
    ICD
    Inscrit en
    Juin 2002
    Messages
    507
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : ICD
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 507
    Points : 359
    Points
    359
    Par défaut
    j'ai casté mon parametre pool dans la macro pour qu'il soit de type pointeur de 'block_list_head' mais rien n'y fais :
    au lieu de faire

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    #define block_list_init_head(head,pool) \
    do \
    { \
    	linked_list_init_head((struct block_list_head *)(head)); \
    	((struct block_list_head *)(head))->pool = pool; \
    	((struct block_list_head *)(head))->free = 0; \
    } \
    while(0)
    j'ai fais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    #define block_list_init_head(head,pool) \
    do \
    { \
    	linked_list_init_head((struct block_list_head *)(head)); \
    	((struct block_list_head *)(head))->pool = ((struct block_list_head *)(head))->pool; \
    	((struct block_list_head *)(head))->free = 0; \
    } \
    while(0)

Discussions similaires

  1. [XL-2007] Probleme avec une macro copier coller
    Par young 25 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 25/02/2012, 10h37
  2. Réponses: 7
    Dernier message: 08/05/2009, 11h58
  3. Réponses: 2
    Dernier message: 12/05/2007, 01h57
  4. Probleme de conversion entre . et , avec une macro excel
    Par fmris dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 18/01/2007, 22h26
  5. Réponses: 3
    Dernier message: 17/11/2006, 14h35

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