Thread: lots of warnings

  1. #1
    Registered User
    Join Date
    Aug 2023
    Posts
    45

    Question lots of warnings

    Code:
    struct TResWord {
        char       *pString;  // ptr to word string
        TTokenCode  code;     // word code
    };
    
    
    static TResWord rw2[] = {
        {"do", tcDO}, {"if", tcIF}, {"in", tcIN}, {"of", tcOF},
        {"or", tcOR}, {"to", tcTO}, {NULL},
    };
    In my project I have lots of arrays of TResWord like rw2[] above. I get the following warning for each array. The warning message is:
    warning: ISO C++ forbids converting a string constant to 'char*' Is there a way to keep the compiler happy?
    maxcy / wt1v

  2. #2
    Registered User Sir Galahad's Avatar
    Join Date
    Nov 2016
    Location
    The Round Table
    Posts
    277
    It just means the struct member 'pString' should be declared const (hence the complaint, "converting a string constant to 'char*'").

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    We did the const char * thing recently.
    deprecated char *
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need lots of help with functions.
    By jp5a9852 in forum C Programming
    Replies: 4
    Last Post: 10-30-2012, 12:09 AM
  2. I'm new and need lots of help
    By metallic806 in forum C++ Programming
    Replies: 7
    Last Post: 03-19-2004, 04:50 PM
  3. Lots of RPG questions...
    By Kyoto Oshiro in forum Game Programming
    Replies: 22
    Last Post: 07-21-2002, 10:47 PM
  4. what you lots think?
    By hermit in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-17-2002, 06:55 AM

Tags for this Thread