const ints as Message IDs = Recompile Everything
I'm hoping for confirmation of what I just told someone. We have a large software project that is divided out into several libraries (.so). The message definitions are all in one library with a set of .h files for the declarations. The message ids are in the .h as const int (see below). One uses the id to subscribe/publish the message.
They had to go and renumber the message ids. They were hoping just to drop in the new library.
I said that they have to recompile all the source that uses the library.
Const objects are internal linkage by default, so the external code that uses the id is not linked to an object changed by the library, rather it is a simple integer that is now out of sync with the library.
I feel very sure that I am right about this.... Or am I all wet?
namespace AppsMessages
{
const Data开发者_JAVA技巧ClassID_t CommandReqId(120097);
class CommandRequestMessage { ... };
}
You are correct.
A better design (at least in terms of mitigating maintenance nightmares like this one) would be to declare these ID objects extern
in the header, and define them once in the library source. Then you'd just have had to drop in the new library.
精彩评论