【问题标题】:Pebble C TupletCString compile errorPebble C TupletCString 编译错误
【发布时间】:2014-03-09 23:15:17
【问题描述】:

我在编译我的 pebble watchapp 时遇到问题。我正在尝试将字符串发送到手机上的 Pebbl eJS 脚本,例如:

Tuplet password_tuple = TupletCString(PASSWORD_KEY, password_str);
Tuplet email_tuple = TupletCString(EMAIL_KEY, email_str); 

编译器错误是:(他们都这样报错,这只是下面的输出行之一)

./src/app_test.c:84:25: error: the address of 'email_str' will always evaluate as 'true'   [-Werror=address]

email_str 和 password_str 在程序顶部定义,如下所示:

static char email_str[30];
static char password_str[30];
#define PASSWORD_PKEY (int32_t)21
#define EMAIL_PKEY (int32_t)20

有人注意到这有什么问题吗?

【问题讨论】:

    标签: pebble-watch pebble-sdk


    【解决方案1】:

    @ismail-badawi 的回答非常正确。

    Pebble 现在建议您使用dict_write_cstring

    dict_write_cstring(&iter, SOME_STRING_KEY, string);
    

    【讨论】:

      【解决方案2】:

      这当然不是很明显,但事实证明这是因为TupletCString 是一个宏,它会扩展为一个包含email_str ? strlen(email_str) + 1 : 0 作为子表达式的表达式,这就是导致错误的原因,因为@987654324 @ 不能为 null,因此比较没有任何作用。

      我找到了this thread on the Pebble forums 并给出了解释。建议的解决方法是定义您自己的没有条件的宏,例如

      #define MyTupletCString(_key, _cstring) \
      ((const Tuplet) { .type = TUPLE_CSTRING, .key = _key, .cstring = { .data = _cstring, .length = strlen(_cstring) + 1 }})
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多