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 :

Problème de pointeurs en paramètres.


Sujet :

C

  1. #1
    Membre actif
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Août 2005
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Enseignant Chercheur

    Informations forums :
    Inscription : Août 2005
    Messages : 45
    Par défaut Problème de pointeurs en paramètres.
    Voici mon problème :
    J'ai une série de pointeurs qui désignent un int.
    Avant l'appel à la fonction, aucun problème, les valeurs sont bonnes après controle sur la console.
    J'apelle une fonction en leur passant ce pointeur en paramètres.
    Et là, c'est le drame : la même ligne n'affiche pas les mêmes résultats...

    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    ...
    printf("%d %d\n", l ->first -> coor -> x, l -> first -> coor -> y);
    int d = search(l);
     
     
    int search(list* l)
    {
    	printf("%d %d\n", l -> first -> coor -> x, l -> first -> coor -> y);
    ...
    }
    Citation Envoyé par Console
    1 4
    Bus error

  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
    Peut tu nous donner ce qu'est ta structure list, comment l est déclaré.

    Deuxième chose, étant donné que tu ne fais que des printf, le plantage n'est peut-être pas à cet endroit, utilise des fprintf sur stderr si tu veux debugger.

    Enfin, affiche au début de ta fonction search l'adresse de l.

  3. #3
    Membre actif
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Août 2005
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Enseignant Chercheur

    Informations forums :
    Inscription : Août 2005
    Messages : 45
    Par défaut
    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    typedef struct
    {
    	int length;
    	struct node* first;
    } list;
    sachant que
    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    struct node
    {
    	coordinates* coor;
    	struct node* next;
    };

    Il s'agit d'une liste chaînée.

    Le problème viens pas forcément du printf, mais je ne comprends pas ce qui empeche l'affichege du 2ème printf alors qu'il n'y à qu'un appel de fonction entre les 2 printf...

  4. #4
    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
    Et l comment est-il déclaré ?

  5. #5
    Membre actif
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Août 2005
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Enseignant Chercheur

    Informations forums :
    Inscription : Août 2005
    Messages : 45
    Par défaut
    Après avoir affiché l on obtient ceci sur la console :
    Citation Envoyé par Console
    1 4
    4194992
    Bus error
    Le problème serait donc dans le printf ???

    Déclaration de l :

    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    list *l = malloc(sizeof(list));
    add(l, c);

    Sachant que add ajoute un noeud à la liste.

  6. #6
    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
    Tu l'a affiché où ? (met des commentaires en plus parce que des nombres on ne sait pas à quoi ils correspondent )

    Et peux tu nous dire comment tu as déclaré l ?

    PS : tu peux nous mettre un peut plus de code stp...

  7. #7
    Membre actif
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Août 2005
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Enseignant Chercheur

    Informations forums :
    Inscription : Août 2005
    Messages : 45
    Par défaut
    Voili vouilou :

    Citation Envoyé par Console
    x=1 y=4
    Adresse de l : 4194992
    Bus error

  8. #8
    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
    Désolé, je me suis mal exprimé. Affiche l avant ton appel à la fonction search et après et vérifie qu'il s'agit bien du même pointeur.

  9. #9
    Membre actif
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Août 2005
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Enseignant Chercheur

    Informations forums :
    Inscription : Août 2005
    Messages : 45
    Par défaut
    Effectivement, petit problème : j'ai pas l'adresse;
    Citation Envoyé par Console
    x=1 y=4
    Adresse de l avant l'appel la fonction : 4194992
    Adresse de l apres l'appel la fonction :
    Bus error

  10. #10
    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
    Si ton code n'est pas énorme, peux tu nous en donner une partie qu'on puisse compiler et analyser parce qu'avec les deux lignes de code que tu donnes, c'est pas évident.

  11. #11
    Membre extrêmement actif

    Homme Profil pro
    Ingénieur R&D
    Inscrit en
    Juin 2003
    Messages
    4 506
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 506
    Par défaut
    Tu pourrais préciser dans quel environnement tu es ? Puis l'IDE que tu utilises ?

  12. #12
    Membre actif
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Août 2005
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Enseignant Chercheur

    Informations forums :
    Inscription : Août 2005
    Messages : 45
    Par défaut
    Oki, vla la chose :

    Code C : 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
     
     
    struct node
    {
    	coordinates* coor;
    	struct node* next;
    };
     
    typedef struct
    {
    	int length;
    	struct node* first;
    } list;
     
    typedef struct
    {
    	int length;
    	struct node* first;
    } list;
     
    int main(void)
    {
    	coordinates *c = malloc(sizeof(coordinates)); 
    	c -> x = 1;
    	c -> y = 4;
    	list *l = malloc(sizeof(list));
    	add(l, c);
     
    	printf("x=%d y=%d\n", l -> first -> coor -> x, l -> first -> coor -> y);
    	printf("Adresse de l avant l'appel à la fonction : %d\n", l);
    	int d = search(0,l, c);
    	return 1;
    }
     
     
    int search(int finalIndex, list* l, coordinates* c)
    {
    	printf("Adresse de l apres l'appel à la fonction : \n", l);
    	printf("x : %d y : %d\n", l -> first -> coor -> x, l -> first -> coor -> y);
    	struct node* currentNode = l -> first;
     
     
    	int i;
    	for (i = 0 ; i <= finalIndex ; i++)
    	{
    		if (compare(c, currentNode -> coor)) return i;		
    		currentNode = currentNode -> next;
    	}
    	return -1;
    }

    Je suis sous mac OSX et j'utilise XCode.

  13. #13
    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
    Bon, un conseil, mets les Warnings sur XCode parce que oulà ! (ps: as-tu mis un projet C et pas C++)

    Un autre conseil, pour être aussi sous OSX, pour les petits projets, utilises gcc en ligne de commande avec splint, ça te simplifie la vie.

    Chez moi ton code ne compile pas (et il en est loin !).

    Alors, dans l'ordre :

    Tu n'as pas donné ce qu'était ta structure coordinates (j'ai supposé quelque chose mais j'aimerai être sur de ce que tu as fais).

    Tu as définis deux fois la structure list.

    Après un malloc, testes toujours la valeur de retour, ça evite les bugs.

    Pour afficher la valeur d'un pointeur, utilises %p.

    La fonction d'affichage dans ta fonction search ne compile pas. (il manque un %p )

    Dans ta fonction main, au lieu du return 1, utilises un return EXIT_SUCCESS, c'est plus parlant (d'ailleur au passage, le 1 n'indique pas une bonne terminaison).

  14. #14
    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 Epok__
    Oki, vla la chose :
    Qu'est-ce qu'il faut faire pour avoir le code qui compile ?
    • Voler une vieille ?
    • Tuer le chien ?
    • Voter Sarkoyal ?

    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
    Project   : Forums
    Compiler  : GNU GCC Compiler (called directly)
    Directory : C:\dev\forums2\
    --------------------------------------------------------------------------------
    Switching to target: default
    Compiling: main.c
    main.c:3: error: syntax error before "coordinates"
    main.c:3: warning: no semicolon at end of struct or union
    main.c:5: error: syntax error before '}' token
    main.c:17: error: conflicting types for 'list'
    main.c:11: error: previous declaration of 'list' was here
    main.c: In function `main':
    main.c:20: error: `coordinates' undeclared (first use in this function)
    main.c:20: error: (Each undeclared identifier is reported only once
    main.c:20: error: for each function it appears in.)
    main.c:20: error: `c' undeclared (first use in this function)
    main.c:20: warning: implicit declaration of function `malloc'
    main.c:24: warning: implicit declaration of function `add'
    main.c:25: warning: implicit declaration of function `printf'
    main.c:25: error: dereferencing pointer to incomplete type
    main.c:25: error: dereferencing pointer to incomplete type
    main.c:26: warning: int format, pointer arg (arg 2)
    main.c:27: warning: implicit declaration of function `search'
    main.c:27: warning: unused variable `d'
    main.c: At top level:
    main.c:30: error: syntax error before "coordinates"
    main.c:31: warning: function declaration isn't a prototype
    main.c: In function `search':
    main.c:32: error: `l' undeclared (first use in this function)
    main.c:32: warning: too many arguments for format
    main.c:36: error: `finalIndex' undeclared (first use in this function)
    main.c:38: warning: implicit declaration of function `compare'
    main.c:38: error: `c' undeclared (first use in this function)
    main.c:38: error: dereferencing pointer to incomplete type
    main.c:40: error: dereferencing pointer to incomplete type
    Process terminated with status 1 (0 minutes, 1 seconds)
    16 errors, 10 warnings

  15. #15
    Expert confirmé
    Avatar de Thierry Chappuis
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Mai 2005
    Messages
    3 499
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Suisse

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 499
    Par défaut
    Salut,

    Le code suivant semble fonctionner, et compile chez moi avec gcc en mode parano:

    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
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    #include <stdio.h>
    #include <stdlib.h>
     
    /* Déclaration des structures */
    typedef struct 
    {
    	int x;
    	int y;
    } coordinates;
     
    struct node
    {
    	coordinates* coor;
    	struct node* next;
    };
     
    typedef struct
    {
    	int length;
    	struct node* first;
    } list;
     
    /* Constructeur et destructeur d'un objet de type coodinates + fonction de comparaison*/
     
    coordinates * coordinates_new(int x, int y)
    {
    	coordinates *tmp = malloc(sizeof *tmp);
    	if (tmp == NULL)
    	{
    		fprintf(stderr, "L'allocation a échoué dans coordinates_new()!\n");
    		exit(EXIT_FAILURE);
    	}
    	tmp->x = x;
    	tmp->y = y;
    	return tmp;
    }
     
    int coordinates_compare(coordinates *c1, coordinates *c2)
    {
    	return (c1->x == c2->x) && (c1->y == c2->y);
    }
     
    void coordinates_free(coordinates **c)
    {
            if (*c != NULL)
            {
    	        free(*c);
    	        *c = NULL;
            }
    }
     
    /* Interface pour  une gestion minimaliste de ta liste chaînée. 
        Très incomplet!*/
     
    list * list_new(void)
    {
    	list *tmp = malloc(sizeof *tmp);
    	if (tmp == NULL) /* L'allocation a échoué*/
    	{
    		fprintf(stderr, "L'Allocation a échoué dans list_new()!\n");
    		exit(EXIT_FAILURE);
    	}
    	tmp->length = 0;
    	tmp->first = NULL;
    	return tmp;
    }
     
    void list_free(list **pp_l)
    {
    	struct node *current;
    	struct node *tmp;
     
    	if ((*pp_l != NULL) && (tmp = (*pp_l)->first))
    	{
    		for (current = tmp->next; current != NULL; tmp = current, current = current->next)
    		{
    			coordinates_free(&(tmp->coor));
    			free(tmp);
    		}
    		coordinates_free(&(tmp->coor));
    		free(tmp);
     
    		free(*pp_l), *pp_l = NULL;
    	}
    }
     
     
    int list_add(list *lst, coordinates *c)
    {
    	int result;
    	struct node *tmp = malloc(sizeof *tmp);
    	if (tmp != NULL)
    	{
    		tmp->coor = c;
    		tmp->next = lst->first;
    		lst->first = tmp;
    		(lst->length)++;
     
    		result = EXIT_SUCCESS;
    	}
    	else
    	{
    		fprintf(stderr, "Allocation failed in add()!\n");
    		result = EXIT_FAILURE;
    	}
    	return result;
    }	
     
     
    int list_search(list* l, coordinates* c)
    {
    	int i;
    	struct node* currentNode = NULL;
     
    	for (i = 1, currentNode = l->first; currentNode != NULL; currentNode = currentNode->next)
    	{
    		if (coordinates_compare(c, currentNode->coor)) 
    		{
    			return i;	
    		}
    		++i;
    	}
    	return -1;
    }
     
     
    /* Main entry point! */
     
    int main(void)
    {
    	int index;
    	list *lst = NULL;
    	coordinates *c1;
    	coordinates *c2;
    	coordinates *c3;
     
            /* On crée quelques objets coordonnées*/
    	c1 = coordinates_new(1, 4);
    	c2 = coordinates_new(10, 40);
    	c3 = coordinates_new(100, 400);
     
            /* On crée une nouvelle liste*/
    	lst = list_new();
     
            /* On ajoute des éléments à la liste */
    	list_add(lst, c1);
    	list_add(lst, c2);
    	list_add(lst, c3);
     
            /* On recherche la position d'un objet dans la liste */
    	index = list_search(lst, c3);
     
    	if (index != -1)
    	{
    		printf("La position de l'objet cherché est %d\n", index);
    	}
    	else
    	{
    		printf("L'élément recherché n'a pas été trouvé!\n");
    	}
     
            /* Bien sûr, ne pas oublier de détruire la liste*/
    	list_free(&lst);
     
    	return EXIT_SUCCESS;
    }
    Thierry
    "The most important thing in the kitchen is the waste paper basket and it needs to be centrally located.", Donald Knuth
    "If the only tool you have is a hammer, every problem looks like a nail.", probably Abraham Maslow

    FAQ-Python FAQ-C FAQ-C++

    +

  16. #16
    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
    Citation Envoyé par splint
    test.c: (in function coordinates_compare)
    test.c:40:9: Return value type boolean does not match declared type int:
    (c1->x == c2->x) && (c1->y == c2->y)
    To make bool and int types equivalent, use +boolint.
    test.c: (in function coordinates_free)
    test.c:47:15: Unqualified storage *c passed as only param: free (*c)
    Unqualified storage is transferred in an inconsistent way. (Use
    -unqualifiedtrans to inhibit warning)
    test.c:50:2: Function returns with null storage derivable from parameter *c
    A possibly null pointer is reachable from a parameter or global variable that
    is not declared using a /*@null@*/ annotation. (Use -nullstate to inhibit
    warning)
    test.c:48:15: Storage *c becomes null
    test.c: (in function list_new)
    test.c:65:9: Null storage tmp->first derivable from return value: tmp
    Function returns a possibly null pointer, but is not declared using
    /*@null@*/ annotation of result. If function may return NULL, add /*@null@*/
    annotation to the return value declaration. (Use -nullret to inhibit warning)
    test.c:64:15: Storage tmp->first becomes null
    test.c: (in function list_free)
    test.c:73:25: Right operand of && is non-boolean (struct node *):
    (*pp_l != NULL) && (tmp = (*pp_l)->first)
    The operand of a boolean operator is not a boolean. Use +ptrnegate to allow !
    to be used on pointers. (Use -boolops to inhibit warning)
    test.c:78:9: Only storage tmp->coor (type coordinates *) derived from released
    storage is not released (memory leak): tmp
    A storage leak due to incomplete deallocation of a structure or deep pointer
    is suspected. Unshared storage that is reachable from a reference that is
    being deallocated has not yet been deallocated. Splint assumes when an object
    is passed as an out only void pointer that the outer object will be
    deallocated, but the inner objects will not. (Use -compdestroy to inhibit
    warning)
    test.c:79:3: Clauses exit with tmp referencing only storage in for body, local
    storage if for loop body does not execute
    The state of a variable is different depending on which branch is taken. This
    means no annotation can sensibly be applied to the storage. (Use -branchstate
    to inhibit warning)
    test.c:75:61: Storage tmp becomes only (through alias current)
    test.c:79:3: Clauses exit with current referencing local storage in for body,
    only storage if for loop body does not execute
    test.c:78:9: Storage current becomes only
    test.c:78:9: Storage current becomes only
    test.c:83:8: Only storage *pp_l->first (type struct node *) derived from
    released storage is not released (memory leak): *pp_l
    test.c:83:8: Unqualified storage *pp_l passed as only param: free (*pp_l)
    test.c:85:2: Only storage current not released before return
    A memory leak has been detected. Only-qualified storage is not released
    before the last reference to it is lost. (Use -mustfreeonly to inhibit
    warning)
    test.c:81:8: Storage current becomes only
    test.c:85:2: Function returns with null storage derivable from parameter *pp_l
    test.c:83:24: Storage *pp_l becomes null
    test.c: (in function list_add)
    test.c:94:3: Implicitly temp storage c assigned to implicitly only:
    tmp->coor = c
    Temp storage (associated with a formal parameter) is transferred to a
    non-temporary reference. The storage may be released or new aliases created.
    (Use -temptrans to inhibit warning)
    test.c:105:2: Variable c is kept in true branch, but not kept in false branch.
    test.c:105:2: in true branch:
    test.c:94:3: Storage c becomes kept
    test.c: (in function list_search)
    test.c:117:7: Test expression for if not boolean, type int:
    coordinates_compare(c, currentNode->coor)
    Test expression type is not boolean or int. (Use -predboolint to inhibit
    warning)
    test.c: (in function main)
    test.c:146:2: Return value (type int) ignored: list_add(lst, c1)
    Result returned by function call is not used. If this is intended, can cast
    result to (void) to eliminate message. (Use -retvalint to inhibit warning)
    test.c:147:2: Return value (type int) ignored: list_add(lst, c2)
    test.c:148:2: Return value (type int) ignored: list_add(lst, c3)
    test.c:165:22: Fresh storage lst not released before return
    A memory leak has been detected. Storage allocated locally is not released
    before the last reference to it is lost. (Use -mustfreefresh to inhibit
    warning)
    test.c:143:2: Fresh storage lst created
    test.c:165:22: Fresh storage c1 not released before return
    test.c:138:2: Fresh storage c1 created
    test.c:165:22: Fresh storage c2 not released before return
    test.c:139:2: Fresh storage c2 created
    test.c:165:22: Fresh storage c3 not released before return
    test.c:140:2: Fresh storage c3 created
    test.c:25:15: Function exported but not used outside test: coordinates_new
    A declaration is exported, but not used outside this module. Declaration can
    use static qualifier. (Use -exportlocal to inhibit warning)
    test.c:36:1: Definition of coordinates_new
    test.c:38:5: Function exported but not used outside test: coordinates_compare
    test.c:41:1: Definition of coordinates_compare
    test.c:43:6: Function exported but not used outside test: coordinates_free
    test.c:50:1: Definition of coordinates_free
    test.c:55:8: Function exported but not used outside test: list_new
    test.c:66:1: Definition of list_new
    test.c:68:6: Function exported but not used outside test: list_free
    test.c:85:1: Definition of list_free
    test.c:88:5: Function exported but not used outside test: list_add
    test.c:107:1: Definition of list_add
    test.c:110:5: Function exported but not used outside test: list_search
    test.c:124:1: Definition of list_search

    Finished checking --- 29 code warnings
    On est d'accord, certains warnings n'ont rien d'inquiètant

  17. #17
    Membre actif
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Août 2005
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Enseignant Chercheur

    Informations forums :
    Inscription : Août 2005
    Messages : 45
    Par défaut
    Merci, mujigka, j'ai pu comprendre grâce à ton code ce qu'il manquait : j'ai compris l'importance du malloc pour la variable retournée par une fonction.
    Désolé de pas avoir été plus clair pour les autres, je débute en c...

    Merci à tous.

  18. #18
    Expert confirmé
    Avatar de Thierry Chappuis
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Mai 2005
    Messages
    3 499
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Suisse

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 499
    Par défaut
    Citation Envoyé par PRomu@ld
    On est d'accord, certains warnings n'ont rien d'inquiètant
    J'essaierai d'être plus attentif à ce que j'écris la prochaine fois. Les fuites de mémoire, c'est pas très beau... et ma gestion de la mémoire est catastophique (surtout tôt le matin et tard le soir). Je vais essayer de le corriger lorsque j'en aurai le temps et de fournir une version plus propre. Merci PRomu@ld, grâce à toi, j'ai découvert splint... même si ça fait pas toujours plaisir.

    Au passage, les erreurs qu'il me donne sur les boolean, je les ignore? Je ne connais pas de type bool en C90.

    Thierry
    "The most important thing in the kitchen is the waste paper basket and it needs to be centrally located.", Donald Knuth
    "If the only tool you have is a hammer, every problem looks like a nail.", probably Abraham Maslow

    FAQ-Python FAQ-C FAQ-C++

    +

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

Discussions similaires

  1. Problème de pointeur en paramètre
    Par sweet live dans le forum Langage
    Réponses: 1
    Dernier message: 16/10/2012, 09h59
  2. Problème de pointeur
    Par toma_lille dans le forum C++
    Réponses: 1
    Dernier message: 07/12/2004, 21h26
  3. problème de passage de paramêtre sous mozilla
    Par mat10000 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 27/09/2004, 10h48
  4. [MFC] Problème de pointeur !!
    Par acastor dans le forum MFC
    Réponses: 7
    Dernier message: 19/03/2004, 15h50
  5. TBitmap et problèmes de pointeurs...
    Par benj63 dans le forum C++Builder
    Réponses: 8
    Dernier message: 28/07/2003, 13h39

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