|Re: [paho-dev] Using C++ with the Paho C client library|
On 16/05/13 13:54, Frank Pagliughi wrote:
Hello All,it's been my plan to have a C++ wrapper for the C APIs. If you are able to contribute your code to this project, that would be great. If not, I'll do my own. That's the place for proper C++ conformance.
(1) Make the headers C++ aware internally:Once the C++ wrapper is written, then C++ programs can use that, and this would become moot. I have a preference for keeping C++ related stuff out of the C code, but I can see the logic.
When I've used const in the past, it's only caused pain. This is the description of const in K&R 2nd Edition:(2) Observe proper const-ness for pointer parameters if there is no intent in updating the item, particularly "const char*" for "char*"
"The const and volatile properties are new with the ANSI standard. The purpose of const is to announce objects that may be placed in read-only memory, and perhaps to increase opportunities for optimization."
Which is not the same as the purpose here. In the latest version of gcc on my machine, using const seems not to cause the problems I was expecting, but I'd have to check on all the compilers we use, MS, and old versions of gcc, before adding this change.
Shouldn't the definition for clientId for example, be "const char const * clientId"? That is, both the pointer and the contents are immutable.
(3) Use const values instead of #define whenever possible, since #define has no respect for namespaces, etc.
See above. I've encountered pain when this before when this should be simple. This is better done in a C++ header I think.
(4) Use "size_t" instead of "int" to specify array lengths, to prevent signed/unsigned warnings when using STL containers:
That makes sense. I'll have to check if it causes any backward compatibility issues.
Back to the top