开发者

STRINGZ_TO_NPVARIANT in xcode problem

开发者 https://www.devze.com 2023-03-19 03:25 出处:网络
have folowing code: NPVariant type; STRINGZ_TO_NPVARIANT(\"click\", type); and the xcode returns \"error: expected expression before \'uint32_t\'\"开发者_如何学JAVA

have folowing code:

NPVariant type;
STRINGZ_TO_NPVARIANT("click", type);

and the xcode returns

"error: expected expression before 'uint32_t'"开发者_如何学JAVA

anyone can give me a hand with this?


I ran into this as well. Based on this bug i found in the npapi project, i solved the problem by not using the macro, and using what it expands to instead, then applying what the patch shows. http://code.google.com/p/npapi-headers/issues/detail?id=3

- NPString str = { _val, uint32_t(strlen(_val)) };

+ NPString str = { _val, (uint32_t)(strlen(_val)) };

Basically, wrap uint32_t in parenthesis, then gcc will compile it.

So the full replacement for the macro is

NPVariant type;
type.type = NPVariantType_String;
NPString str = { "click", (uint32_t)(strlen("click")) };
type.value.stringValue = str;


If you check what this macro resolves into you get:

NPVariant type;
type.type = NPVariantType_String;
NPString str = { "click", uint32_t(strlen("click")) };
type.value.stringValue = str;

At least this way one can understand what the error message refers to. I'm still not sure what the reason for the error is however - maybe your Xcode or gcc version is outdated. According to the documentation you need at least Xcode 2.5 and gcc 4.2.


in your npruntime.h find these two MACRO

#define STRINGZ_TO_NPVARIANT(_val, _v)                                        \
NP_BEGIN_MACRO                                                                \
    (_v).type = NPVariantType_String;                                         \
    NPString str = { _val, **(uint32_t)** strlen(_val) };                          \
    (_v).value.stringValue = str;                                             \
NP_END_MACRO

#define STRINGN_TO_NPVARIANT(_val, _len, _v)                                  \
NP_BEGIN_MACRO                                                                \
    (_v).type = NPVariantType_String;                                         \
    NPString str = { _val, **(uint32_t)**_len };                                  \
    (_v).value.stringValue = str;                                             \
NP_END_MACRO

     add (uint32_t) cast before strlen(_val) and _len

0

精彩评论

暂无评论...
验证码 换一张
取 消