###前提・実現したいこと
c言語でハッシュテーブルのプログラムを組んでいます、見たことのない警告が出たので、出た理由をしりたく、質問します
###発生している問題・エラーメッセージ
ChainHash.c:14: warning: assignment discards qualifiers from pointer target type
###該当のソースコード #include <stdio.h> #include <stdlib.h> #include "Member.h" #include "ChainHash.h" /*ハッシュ関数*/ static int hash( int key, int size ) { return key % size; } /*ノードの各メンバに値を設定*/ static void SetNode( Node *n, const Member *x, const Node *next ) { n->data = *x; n->next = next; } /*ハッシュ表の初期化*/ int Initialize( ChainHash *h, int size ) { int i; if( ( h->table = calloc( size, sizeof( Node * ) ) ) == NULL ) { h->size = 0; return 0; } h->size = size; for( i = 0; i < size; i++ ) { h->table[ i ] = NULL; } return 1; } /*データの検索*/ Node *Search( const ChainHash *h, const Member *x ) { int key = hash( x->no, h->size ); Node *p = h->table[ key ]; /*着目ノード*/ while( p != NULL ) { if( p->data.no == x->no ) { return p; } p = p->next; } return NULL; /*探索失敗*/ } /*データの追加*/ int Add( ChainHash *h, const Member *x ) { int key = hash( x->no, h->size ); Node *p = h->table[ key ]; /*着目ノード*/ Node *temp; while( p != NULL ) { if( p->data.no == x->no ) { return 1; } p = p->next; } if( ( temp = calloc( h->size, sizeof( Node ) ) ) == NULL ) { return 2; } SetNode( temp, x, h->table[ key ] ); h->table[ key ] = temp; return 0; /*追加成功*/ } /*データの削除*/ int Remove( ChainHash *h, const Member *x ) { int key = hash( x->no, h->size ); Node *p = h->table[ key ]; /*着目ノード*/ Node **pp = &h->table[ key ]; /*着目ノードへのポインタ*/ while( p != NULL ) { if( p->data.no == x->no ) { *pp = p->next; free( p ); return 0; } pp = &p->next; p = p->next; } return 1; } /*ハッシュ表をダンプ*/ void Dump(const ChainHash *h ) { int i; Node *p = h->table[ i ]; for( i = 0; i < h->size; i++ ) { printf( "%02d " , i ); while( p != NULL ) { printf( "-> %d (%s) ", p->data.no, p->data.name ); p = p->next; } putchar( '\n' ); } } /*全データの削除*/ void Clear( ChainHash *h ) { int i; for( i = 0; i < h->size; i++ ) { Node *p = h->table [ i ]; while( p != NULL ) { Node *next = p->next; free( p ); p = next; } h->table[ i ] = NULL; } } /*ハッシュ表を後始末*/ void Terminate( ChainHash *h ) { Clear( h ); free( h->table ); h->size = 0; }
###試したこと
インターネットで調べてみたところ、なにやらconst修飾子が問題のようですが、しっくりくる、情報が見つけられませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
実行環境 : Centos6.5(final)
コンパイラ : gcc-4.4.7-4.el6.x86_64

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/12 14:43