typedef struct cellule
{
int numero;
int poids;
struct cellule *suivant;
}Celulle, *LISTE;
LISTE graphe[TAILLE];
我不明白*LISTE
是什么意思?
有两种可接受的方法来声明此结构:
typedef struct cellule
{
int numero;
int poids;
struct cellule *suivant;
}Celulle;
// usage:
Celulle c;
或
struct cellule
{
int numero;
int poids;
struct cellule *suivant;
};
// usage:
struct celulle c;
选择哪个是编码风格的问题。到目前为止,前者是最常见的。后者用于Linux风格的程序。都可以。
然而,永远不能将指针隐藏在typedef
后面。您的原始代码执行此操作,定义了类型LISTE
,该类型实际上是Celulle*
指针。像这样隐藏指针会造成混乱,并因此而导致错误。相反,您的原始程序应重写为如下形式:
typedef struct cellule
{
int numero;
int poids;
struct cellule* suivant;
}Celulle;
Celulle* graphe[TAILLE];
已经有很多有关此的信息。
基本上是指向您定义的结构的指针的别名。
typedef struct cellule
{
int numero;
int poids;
struct cellule *suivant;
}Celulle, *LISTE;
可以分割为:
struct cellule
{
int numero;
int poids;
struct cellule *suivant;
};
typedef struct cellule Celulle;
typedef struct cellule * LISTE;
使LISTE成为该结构的Poniter的别名。
*Celulle
和LISTE
是相同的类型。
LISTE graphe[TAILLE];
您正在声明该结构的指针数组(大小为TAILLE)。