Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Using C++ with the Paho C client library

Hello All,

I'm writing C++ wrapper classes around the C library, with the goal to have it mimic the Java API as closely as possible. There are a few minor things in the C library that if updated might help out.

(1) Make the headers C++ aware internally:
#if defined(__cplusplus)
extern "C" {
(2) Observe proper const-ness for pointer parameters if there is no intent in updating the item, particularly "const char*" for "char*"
DLLExport int MQTTAsync_create(MQTTAsync* handle,
        const char* serverURI, const char* clientId, ...
(3) Use const values instead of #define whenever possible, since #define has no respect for namespaces, etc.
const int MQTTASYNC_SUCCESS = 0;
instead of
(4) Use "size_t" instead of "int" to specify array lengths, to prevent signed/unsigned warnings when using STL containers:
DLLExport int MQTTAsync_subscribeMany(MQTTAsync handle, size_t count,
        const char** topic, const int* qos, MQTTAsync_responseOptions* response);

These all make sense in the C realm, but are particularly helpful when working in C++.
Let me know if I can help in any way.


Back to the top