Bonjour,

Je développe un programme sous Linux avec Eclipse/GCC. Mon problème est que lorsque j'utilise l'option -Wunreachable-code, j'ai plusieurs warnings indiquant une ligne qui ne sera jamais exécutée alors qu'il n'y a pas de raison pour ce warning, comme dans le code suivant :

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
/**
 * Gives the hash table's node containing the value referenced by key.
 * @param t Address of the hash table. If NULL, nothing is done.
 * @param key Key from which the function will search the node. If NULL, nothing is done.
 * @param hashed_index If not NULL, will be fitted with the hash value.
 * @return Node containing the value referenced by key.
 */
static struct node *lookup(const Hashtable *t, const char *key, unsigned long *hashed_index)
{
 
	struct node *current = NULL; /* Used to loop through the collision list, and store the address of the searched node */
 
	if (t != NULL && key != NULL)
	{
 
		unsigned long hi; /* Hash index */
 
		/* Computing the hash value and copying it in hashed_index if necessary */
		hi = hash(t, (const unsigned char *)key);
		if (hashed_index != NULL)
			*hashed_index = hi; /* Warning : ce code ne sera jamais exécuté */
 
		/* Getting the searched node */
		for (current = t->table[hi]; current != NULL && strcmp(current->key, key) != 0; current = current->next)
			;
 
	}
 
	return current;
 
}
Quel est le problème (en mode Debug avec les mêmes options, aucun warning) ?

Une autre petite question à propos des options de compilations : quelle est la différence entre -ansi et -pedantic ? S'il n'y a aucun avertissement ni erreur, cela veut-il dire que le code est utilisable tel quel sur toutes les plate-fromes ?