私はデキューを破壊しようとしていますが、何とかポインタで失敗します。私は次のコードを書いています(両端キューは、両端キューの最初の要素を指すポインタへのポインタです)。 DequeItemは次のフィールド(次の要素へのポインタ)とデータ(void *)を持つ構造体です。ポインタを使用してdequeとC言語でフリー
void deque_destroy(DequeItem **deque) {
DequeItem *temp;
DequeItem *item;
for (item = *deque; item != NULL; item = temp) {
printf("%d", *((int*)((item)->data)));
temp = item->next;
free(item);
}
}
構造体宣言は次のとおりです。
struct DequeItem {
void *data; // Data stored in the deque item
struct DequeItem *previous; // Pointer to the previous DequeItem in the ring
struct DequeItem *next; // Pointer to the next DequeItem in the ring
};
typedef struct DequeItem DequeItem;
それでは、正確には何が動作していませんか? –
セグメント違反が発生します。理由:プログラムが受信した信号EXC_BAD_ACCESS、メモリにアクセスできない 理由:13のアドレス:0x0000000000000000だから、私はヌルポインタを持っていますか? – rize
セグメンテーションフォルトは、 forループのため、printf()。 – rize