我试图找出从C中的void*函数调用返回一个整数的正确方法.
即......
#include <stdio.h>
void *myfunction() {
int x = 5;
return x;
}
int main() {
printf("%d\n", myfunction());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但我一直在:
警告:返回从整数中生成指针而不进行强制转换
我需要做一个演员来完成这项工作吗?它似乎没有问题地返回x,真正的myfunction返回指向结构和字符串的指针,它们都按预期工作.
我一直在尝试解析嵌套的JSON响应而不将信息映射到预定义的结构.
使用空白界面,它会返回:
map[name:My Folder parentId:1 created:2014-10-09T16:32:07+0000 deleted:false description:Sync Dir id:3 links:[map[rel:self entity:folder href:https://web.domain.org/rest/folders/3 id:3] map[href:https://web.domain.org/rest/folders/1 id:1 rel:parent entity:folder] map[entity:user href:https://web.domain.org/rest/users/1 id:1 rel:creator]] modified:2014-12-18T18:07:01+0000 permalink:https://web.domain.org/w/SpJYGQkv syncable:true type:d userId:1]
所以我使用以下内容来浏览此信息:
func NFind(input interface{}, refs...interface{}) (output interface{}) {
defer func() {if r := recover(); r != nil { output = nil }}()
for _, ref := range refs {
switch cur := ref.(type) {
case string:
output = input.(map[string]interface{})[cur]
case int:
output = input.([]interface{})[cur]
}
}
return output
}
func NMap(input interface{}) (output …Run Code Online (Sandbox Code Playgroud)