c - C 中的 R3Route URL 路由器

标签 c url-routing

我尝试在 C 语言和 github 页面 https://github.com/c9s/r3 上使用 R3Route URL 路由器我看到以下内容:

#include <r3/r3.h>

// create a router tree with 10 children capacity (this capacity can grow dynamically)
R3Node *n = r3_tree_create(10);

int route_data = 3;

// insert the R3Route path into the router tree
r3_tree_insert_path(n, "/bar", &route_data); // ignore the length of path

有人可以告诉我这里的route_data是什么吗?为什么是3?

谢谢

最佳答案

我刚刚检查了这个库的源代码,发现了这个:

#define r3_tree_insert_path(n,p,d) r3_tree_insert_pathl_ex(n,p,strlen(p), NULL, d, NULL)

其中 d 是你的 int = 3

这是该函数的新原型(prototype)

R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, int path_len, R3Route * route, void * data, char **errstr)

在这个函数中,数据仅在这一行使用

if (route) {
        route->data = data;
}

route是一个结构体,其定义可以在r3.h中找到

我在代码中到处搜索这个 int 但没有成功..

如果您使用此结构(R3Route),则通过在结构中将参数传递为 void * 可能会很有用,但您应该尝试将 int * 更改为 NULL 并尝试执行您的程序。我并不是很有用,因为我不知道这个库,但这就是我发现的一切。 :)

关于c - C 中的 R3Route URL 路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36346461/

相关文章:

python - Pyramid 遍历 __name__ 匹配 View 名称

c - 为什么在 if 条件中 a=4 被评估为 true 而 b=0 被评估为 false?

c - 打印链表导致无限循环(C)?

c++ - 如何更改 Eclipse 自动生成的标题注释?

asp.net - Aps.Net 4.0 网络表单路由有效但没有避免 css jpg js 文件

c# - 站点地图/面包屑未在默认页面上显示 Url 路由

javascript - AngularJS UI 路由器 : Rendering parent partial with child partial

javascript - Backbone.JS 或 Marionette.JS 路由,无需哈希更改依赖

php - 发送 : How to correctly destruct a custom object in PHP 7?

c++ - 是否有导致 50% 分支预测未命中的代码?