我正在尝试使用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