Posted to tcl by kbk at Thu Apr 26 21:38:23 GMT 2012view raw

  1. extern "C" {
  2. typedef struct KeyValue {
  3. char* key;
  4. int value;
  5. } KeyValue;
  6. }
  7. static const KeyValue pairs[] = {
  8. { "fred", 0 },
  9. { "barney", 1 }
  10. };
  11. const KeyValue* getPairs() {
  12. return pairs;
  13. }
  14.  
  15.  
  16.  
  17. example.cpp:10:1: warning: deprecated conversion from string constant to char* [-Wwrite-strings]
  18. example.cpp:10:1: warning: deprecated conversion from string constant to char* [-Wwrite-strings]

Comments

Posted by jenglish at Fri Apr 27 01:24:25 GMT 2012 [text] [code]

Change the declaration to: struct KeyValue { const char *key; // <== note addition of const int value; }; and the initializer should work.