title: Implementing compile-time mechanism checking uniqueness of a string
body: <p>The simplest way of defining my problem is that I'm trying to implement a mechanism that would check whether the same string had already been used (or a pair (number, string)). I would like this mechanism to be implemented in a smart way using C preprocessor. I would also like that this mechanism gave me compile errors when there is a conflict or run-time errors in Debug mode (by checking assertions). We don't want the developer to make a mistake when adding a message, as every message should be unique. I know that it could be done by calculating a hash or for example <strong>crc</strong>/<strong>md5</strong> but this mechanism would be conflict-vulnerable which I need to avoid. It is crucial that every message can be used only once. </p>
  
  <p>Example behaviour of this mechanism: </p>
  
  <pre><code>addMessage(1, "Message1") //OK 
  addMessage(2, "Message2") //OK 
  . 
  . 
  . 
  addMessage(N, "MessageN") //OK 
  addMessage(2, "Message2") //Compile error, Message2 has already been used 
  </code></pre>
  
  <p>Alternative behaviour (when Debugging code): </p>
  
  <pre><code>addMessage(1, "Message1") //OK 
  addMessage(2, "Message2") //OK 
  . 
  . 
  . 
  addMessage(N, "MessageN") //OK 
  addMessage(2, "Message2") //Assertion failed, because Message2 has already been used 
  </code></pre>
  
  <p>The preferred way of doing it would be smart usage of <strong>#define</strong> and <strong>#undef</strong> directives. In general the preprocessor should be used in a smart way (I am not sure if this is possible) maybe it can be achieved by appropriate combinations of macros? Any C preprocessor hacker that could help me solve this problem? </p>
  
  <p>//EDIT: I need those messages to be unique globally, not only inside one code block (like function of if-statement). </p>
  
  <p>//EDIT2: The best description of the problem would be that I have 100 different source files and I would like to check with a preprocessor (or possibly other mechanism other than parsing source files with a script at a start of the compilation every-time, which would be very time-consuming and would add another stage to an enough complicated project) if a string (or a preprocessor definition) was used more than one time. I still have no idea how to do it (I know it may not be possible at all but I hope it actually is). </p>