私はすべてのように見える構造の束を持っています
typedef struct {
A[1..100] *next; // this is not an array, just indicating A1 or A2 or A3 and so on
//other stuff that varies from struct to struct
} A[1..100] // A1, A2, and so on
異なる同じタイプの構造のリンクリストをいくつか生成します。関数のどこかに、次のようなメモリを割り当てます
A55 *struct_list;
A55 *next_in_list;
struct_list = (A55 *)malloc(sizeof(A55));
(*struct_list).next = NULL;
//some loop
next_in_list = (A55 *)malloc(sizeof(A55));
(*next_in_list).next = struct_list;
struct_list = next_in_list;
ループstruct_list
の最後には、リンクリストの最後へのポインタがあります。
リストに入力する構造に関係なく、リストを解放する単一の関数が必要です。次のことがうまくいくと思いますが、ルールに違反せず、実装が安全である可能性のあるものが必要です。
void freeStruct(*void start){
void ** current, * next;
current = (void **) start;
do{
next = *current;
free(current);
current = (void **) next;
}while(current != NULL)
}
私の質問は、NULLが、を含むすべての型へのすべてのポインタに対して同じ数値を持っているかどうかstruct
です。そして、異なるstruct
定義に対して同じ関数を100回コピーする必要なしに、これを行うためのより良い方法はありますか?