Thread: GCC compiler warning???

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    91

    GCC compiler warning???

    Hello all...
    I am getting a warning from my compiler and would like to know how to resolve it??

    I have an h file with the following code:
    Code:
    typedef struct mainScreen_t{
        uint8_t line;
        uint8_t position;
        char value[16];
    }mainScreen_t;
    
    
    const mainScreen_t Screen1 = {0, 10, {"GPS"}};
    const mainScreen_t Screen2 = {1, 10, {"A/D"}};
    In my c file I have:
    Code:
    mainScreen_t *lvl_1[LCD_MAIN_MENUS] = {&Screen1, &Screen2};
    LCD_MAIN_MENUS is a #define .

    The warning which I receive:
    #145-D a value of type "const mainScreen_t *" cannot be used to initialize an entity of type "mainScreen_t *"



    Implementing the following line of code does not yield any warning:

    Code:
    mainScreen_t lvl_1[LCD_MAIN_MENUS] = {{0, 10, {"GPS"}}, {1, 10, {"A/D"}}};
    Thanks for the help!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You asked this already, but you never responded.
    Coding question? Following yields error, not sure how to fix?
    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.

  3. #3
    Registered User
    Join Date
    Apr 2021
    Posts
    140
    You declared the Screen1 and Screen2 symbols as being const. But your lvl_1 is declared as an array of pointers to non-const items.

    You need to either change the declaration of the const symbols to be non-const, or change the declaration of the pointers to indicate they are to const items.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler warning
    By Madhavi in forum C Programming
    Replies: 8
    Last Post: 06-09-2016, 10:46 AM
  2. Compiler Warning
    By samuelmoneill in forum C Programming
    Replies: 5
    Last Post: 04-16-2009, 06:57 AM
  3. Compiler warning
    By drnaphtali in forum C Programming
    Replies: 2
    Last Post: 11-07-2008, 11:16 AM
  4. compiler warning still won't go away
    By trprince in forum C Programming
    Replies: 1
    Last Post: 11-30-2007, 08:35 PM
  5. Why compiler warning?
    By cdave in forum C Programming
    Replies: 16
    Last Post: 09-06-2004, 01:03 AM

Tags for this Thread