warning: comparison with string literal results in unspecified behavior [-Waddress]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I have a piece of code which is called very frequently, but should output
diagnostic messages only if it had actually changed:

   #define CHECK(func, message)                    \
       if(!(func)) {                                       \
           if (DEBUG && reason!=message) {                         \
               reason = message;                                   \
               printf("invalid configuration: %s\r\n", message);   \
           }                                                       \
           return 0;                                               \
       }
   
   int valid_config (void)
   {
     static char *reason=NULL;
   
     CHECK(check_magics(), "magic numbers");
     CHECK(config_ptr_valid(configvers), "configvers ptr");
     CHECK(config_ptr_valid(configexec), "configexec ptr");
     CHECK(strncmp (configexec, COMPATVERSION, sizeof(COMPATVERSION))>=0, "compatibility");
     CHECK(!strncmp(configvers,version(),SIGNIFICANT_VERSION_LETTERS), "version mismatch");
   
     return 1;
   }

With this code, I get the warning that comparing with a string literal is
unspecified.

A search on google finds me lots of explanations about confusing pointers with
strings. But in this case, I _do_ remember the pointer to the literal and
want to do a pointer comparison. Doing strcpy/strcmp here is not an option,
since this function is called very frequently.

Is there any reason, that a pointer to a string literal can change?

-- 
Josef Wolf
jw@xxxxxxxxxxxxx



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux