title: C macro's argument limiting by argument prefix
body: <p>I have a set of defined macros as follows.</p>
  <pre><code>    #define ARM_FRONT_REG   1
      ..............
      #define ARM_REAR_REG   10
      
      
      #define MOTOR_MAIN_REG   1
      ..............
      #define MOTOR_AUX_REG   3
      
      
      #define MOTOR_REGISTER_ADDRESS(register_offset)      \
           (                                               \
                  addr = MOTOR_BASE_ADDR * (1 &lt;&lt; BITS_PER_MODULE) + register_offset)                  \                               
            )                                              \
      
      #define ARM_REGISTER_ADDRESS(register_offset)      \
           (                                               \
                  addr = ARM_BASE_ADDR * (1 &lt;&lt; BITS_PER_MODULE) + register_offset)                  \                               
            )                                              \
  </code></pre>
  <p>I am using macros like</p>
  <pre><code>ui_address = ARM_BASE_ADDR (ARM_REAR_REG)
  ui_address = MOTOR_REGISTER_ADDRESS (MOTOR_MAIN_REG)
  </code></pre>
  <p>I want to restrict macro usage which is mixed with each other. Is there a way of aborting compiling if macros used as following?</p>
  <pre><code>ui_address = ARM_BASE_ADDR (MOTOR_MAIN_REG)
  ui_address = MOTOR_REGISTER_ADDRESS (ARM_REAR_REG)
  </code></pre>
  <p>PS :
  I have mentioned macros in brief, But actual macros are as below, which used to perform register reads write to Linux driver from user application.</p>
  <p>actual struct :</p>
  <pre><code>struct hw_register_struct
  {
      int  log_level;
      unsigned int reg_addr;
      unsigned int reg_value;
      char    reg_name [MAX_REG_NAME_LENGTH];
      char    application_info [APP_INFO_LENGTH];
  };
  </code></pre>
  <p>This macro validates the address is correct per module.</p>
  <pre><code> #define CHECK_ADDR_SUB_MODULE(module_index, sub_module, sub_module_bits, offset, max_reg_count)     
          ({                                                                                              
              unsigned int check_ret = 0;                                                                 
              if(offset &gt;= max_reg_count){                                                               
                  hw_register.reg_addr = 0;                                                           
                  check_ret = 1;                                                                          
              } else {                                                                                    
                  hw_register.reg_addr = (module_index * (1 &lt;&lt; BITS_PER_MODULE) + (1 &lt;&lt; sub_module_bits) * (sub_module) + offset); 
              }                                                                                           
              check_ret;                                                                                  
          })                                                                                              
      
  </code></pre>
  <p>This macro assigns the address to the variable in the struct.</p>
  <pre><code>    #define SEQUENCER_REGISTER_ADDRESS(register_offset)                                       
          ({                                                                                              
              memset((void *)&amp;hw_register, 0, sizeof(struct hw_register_struct));                 
              if(CHECK_ADDR_SUB_MODULE(MODULE_SEQUENCER, 0, register_offset, SEQ_REG_COUNT)){            
                  Logger::Print(ERROR_LEVEL, &quot;Invalid Address | Module : %s | Address : %s&quot;, STR(MODULE_SEQUENCER), #register_offset); 
              }                                                                                           
              memcpy(hw_register.reg_name, #register_offset, sizeof(#register_offset));               
              hw_register.reg_addr;                                                                   
          })                                                                                              
      
      
  </code></pre>
  <p>Perform calling the ioctl to Linux driver</p>
  <pre><code>    #define WRITE_REGISTER_(register_addr, register_value, func, line, log_level_)
          {                                                                                               
              register_addr;                                                                              
              hw_register.reg_value = register_value;                                                 
              hw_register.log_level = log_level_;                                                     
              snprintf(hw_register.application_info, APP_INFO_LENGTH - 1,&quot;%s:%d&quot;, func, line);        
              long ret_ioctl = p_IOCTL-&gt;IOCTL&lt;struct hw_register_struct&gt;(IOCTL_WRITE, hw_register);  
              if(unlikely(ret_ioctl != 0))                                                                
              {                                                                                                
                  Logger::Print(ERROR_LEVEL, &quot;IOCTL WRITE_REGISTER Failed | Reg: %u, Reg Name [ %s ]&quot;, hw_register.reg_addr, hw_register.reg_name);
              }                                                                                           
           }    
      
      
      #define WRITE_REGISTER_INFO(register_addr, register_value) WRITE_REGISTER_(register_addr, register_value, __func__, __LINE__, KERN_INFO_LEVEL)
  </code></pre>