The easiest way to identify my problem is that I am trying to implement a mechanism that would check if the same string (or a pair (number, string)) has already been used. I would like this mechanism to be implemented intelligently using the C preprocessor. I would also like this mechanism to allow me to compile errors when there are conflicts or errors during execution in debug mode (by checking statements). We do not want the developer to make a mistake when adding a message, since each message must be unique. I know that this can be done by computing a hash or, for example, crc / md5but this mechanism will be vulnerable to conflict, which I must avoid. It is imperative that each message can only be used once.
An example of the behavior of this mechanism:
addMessage(1, "Message1")
addMessage(2, "Message2")
.
.
.
addMessage(N, "MessageN")
addMessage(2, "Message2")
Alternative behavior (when debugging code):
addMessage(1, "Message1")
addMessage(2, "Message2")
.
.
.
addMessage(N, "MessageN")
addMessage(2, "Message2")
The preferred way to do this would be to use the #define and #undef directives wisely . In general, the preprocessor should be used in a smart way (I'm not sure if this is possible), maybe this can be achieved using the appropriate combinations of macros? Any C preprocessor hacker that can help me solve this problem?
// EDIT: I need these messages to be unique throughout the world, and not just inside one block of code (for example, the if-statement function).
//EDIT2: , 100 , (, , , script , ), ( ) . , ( , , , ).