我正在嘗試使用avro-c做一個簡單的字符串setter getter程序。錯誤獲取avro字符串
我的代碼是:
avro_value_t frame_value;
avro_schema_t frame_schema = avro_schema_string();
avro_value_iface_t *frame_iface = avro_generic_class_from_schema(frame_schema);
avro_generic_value_new(frame_iface, &frame_value);
char *name;
int size;
avro_value_set_string(&frame_value,"hello");
avro_value_get_string(&frame_value,name,&size);
printf("\nname is %s",name);
printf("\nsize is %d",size);
但雖然大小是正確的,其是6包括空字符它輸出一個空字符串。我究竟做錯了什麼?
哪個警告做你的編譯器打印?你試圖讓他們沉默的是什麼? – Gerhardh
刪除所有working.size警告應該是size_t類型。我認爲int可以被轉換成size_t。 –
'int'和'size_t'可能有不同的大小。爲什麼'size_t'存在可能是有原因的。 ;)你的編譯器沒有對'name'的錯誤類型嚴重尖叫?除了AndreKampling的答案中顯示的其他缺陷並不容易。如果你的編譯器提供了一個提示,請聽! – Gerhardh