Hi.
I get a thingworx c-sdk and I want to use it My C++ project.
But in thingworx c-sdk, it uses 'namespace' as some parameter's name.
As I know 'namespace' is reserved word in C++.
How can I resolve it?
Solved! Go to Solution.
Hello,
You can't use language reserved keywords as you mentioned correctly.
However, there is a workaround for this using preprocessor macros, but due to compiler variety and complexity I can only offer limited support on this.
You'd have to do the following steps:
1. Ensure C linkage for all C SDK included headers:
extern "C" { #include "targetheader.h" }
2. For cases in which variable names include C++ keywords redefine them within the C linkage scope. (it's still including the header in global scope as expected)
extern "C" { // redefine namespace to another identifier for C linkage. Used namespace_ignore as a sample #define namespace namespace_ignore // include your headers here #include "targetheader.h" // remove redefinition of namespace to continue in C++ #undef namespace
}
Using this method you should be able to properly compile your project, the C SDK is not using a keyword as a identifier for a type, which makes this workaround viable. You're also still able to use the namespace keyword in your C++ code.
Let me know if you have any questions.
Regards,
Pascal
Hello,
You can't use language reserved keywords as you mentioned correctly.
However, there is a workaround for this using preprocessor macros, but due to compiler variety and complexity I can only offer limited support on this.
You'd have to do the following steps:
1. Ensure C linkage for all C SDK included headers:
extern "C" { #include "targetheader.h" }
2. For cases in which variable names include C++ keywords redefine them within the C linkage scope. (it's still including the header in global scope as expected)
extern "C" { // redefine namespace to another identifier for C linkage. Used namespace_ignore as a sample #define namespace namespace_ignore // include your headers here #include "targetheader.h" // remove redefinition of namespace to continue in C++ #undef namespace
}
Using this method you should be able to properly compile your project, the C SDK is not using a keyword as a identifier for a type, which makes this workaround viable. You're also still able to use the namespace keyword in your C++ code.
Let me know if you have any questions.
Regards,
Pascal
Thank you!
Actually I tried it a days ago... at that time, it was not solution.
but this time, it works!
Thank you for your help!