何が間違っているのかわかりません。これが明らかに間違っている場合は申し訳ありませんが、uthash を使用して株式とその価格のハッシュ マップを作成しようとしています。しかし、ハッシュ マップに株を追加すると、上記のエラーが発生します。
私がしたことは、彼らのサイトから例を取り出して実行し、それが機能することを確認することでした。期待どおりに機能したら、問題に合わせて値を変更しました。元のコードではid
、構造体の変数は整数でしたが、それを char に変更しました (数字の代わりに、株式ティッカーをキーとして使用したかったのです)。その後、次のエラーが発生し始めました。
../src/stackCsamples.c:87: warning: passing argument 1 of '__builtin_object_size' makes pointer from integer without a cast
../src/stackCsamples.c:87: warning: passing argument 1 of '__builtin_object_size' makes pointer from integer without a cast
../src/stackCsamples.c:87: warning: passing argument 1 of '__builtin___strcpy_chk' makes pointer from integer without a cast
../src/stackCsamples.c:87: warning: passing argument 1 of '__inline_strcpy_chk' makes pointer from integer without a cast
../src/stackCsamples.c:89: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
../src/stackCsamples.c:89: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
../src/stackCsamples.c:89: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
問題は、ここ(87)strcpy(s->id, user_id);
と(89)の2行にあるようです:HASH_ADD_STR( users, id, s );
これらの両方をどのように間違って使用していますか? strcpy を調べたところ、3 つのアイテムが必要なように見えますが、サイズを追加してもエラーが発生します。
関連があると思われる部分の抜粋を次に示します。
#include <stdio.h> /* gets */
#include <stdlib.h> /* atoi, malloc */
#include <string.h> /* strcpy */
#include "uthash.h"
struct my_struct {
char id; /* key */
float price;
UT_hash_handle hh; /* makes this structure hashable */
};
struct my_struct *users = NULL;
void new_stock(char *user_id, float price) {
struct my_struct *s;
s = (struct my_struct*)malloc(sizeof(struct my_struct));
strcpy(s->id, user_id);
s->price = price;
HASH_ADD_STR( users, id, s ); /* id: name of key field */
}
int main() {
printf("starting..");
new_stock("IBM", 10.2);
new_stock("goog", 2.2);
return 0;
}