首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >smart_str_alloc:错误:未声明的newlen

smart_str_alloc:错误:未声明的newlen
EN

Stack Overflow用户
提问于 2014-08-28 17:04:08
回答 1查看 47关注 0票数 0

我为一个简短的FastCGI脚本使用了smart_str头文件(与PHP无关),但是不能正确地使用smart_str_alloc。我的代码:

代码语言:javascript
复制
smart_str json = {0, 0, 0};
smart_str_alloc(&json, 1024 * 20, 0);

这将产生错误:

代码语言:javascript
复制
php_smart_str.h:72:37: error: ‘newlen’ undeclared (first use in this function)
  smart_str_alloc4((d), (n), (what), newlen)

smart_str_alloc4的宏是:

代码语言:javascript
复制
#define smart_str_alloc4(d, n, what, newlen) do {                   \
    if (!(d)->c) {                                                  \
        (d)->len = 0;                                               \
        newlen = (n);                                               \
        (d)->a = newlen < SMART_STR_START_SIZE                      \
                ? SMART_STR_START_SIZE                              \
                : newlen + SMART_STR_PREALLOC;                      \
        SMART_STR_DO_REALLOC(d, what);                              \
    } else {                                                        \
        newlen = (d)->len + (n);                                    \
        if (newlen >= (d)->a) {                                     \
            (d)->a = newlen + SMART_STR_PREALLOC;                   \
            SMART_STR_DO_REALLOC(d, what);                          \
        }                                                           \
    }                                                               \
} while (0)

smart_str_alloc定义中传递的newlen参数如下所示:

代码语言:javascript
复制
#define smart_str_alloc(d, n, what) \
    smart_str_alloc4((d), (n), (what), newlen)

有趣的是,在PHP源代码中,(来自json.c)使用smart_str_alloc是没有问题的:

代码语言:javascript
复制
smart_str_alloc(buf, len+2, 0);

我遗漏了什么?

EN

回答 1

Stack Overflow用户

发布于 2014-08-28 17:08:25

smart_str_alloc需要在其作用域中定义一个变量newlen

代码语言:javascript
复制
size_t newlen;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25544848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档