Thread: Coding question? Following yields error, not sure how to fix?

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

    Coding question? Following yields error, not sure how to fix?

    Can someone tell me how to fix the following error? I am not a software guy and have tried multiple things but not figured it out.

    H file:
    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"}};
    C file:
    Code:
    mainScreen_t lvl_1[LCD_MAIN_MENUS] = {Screen1, Screen2};
    Error:
    Code:
    "../main.c", line 41: error #28: expression must have a constant value

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I've no idea, it works for me.
    Code:
    $ cat bar.c
    #include <stdio.h>
    #include <stdint.h>
    
    typedef struct mainScreen_t{
        uint8_t line;
        uint8_t position;
        char value[16];
    }mainScreen_t;
    
    #define LCD_MAIN_MENUS 2
     
    const mainScreen_t Screen1 = {0, 10, {"GPS"}};
    const mainScreen_t Screen2 = {1, 10, {"A/D"}};
    
    mainScreen_t lvl_1[LCD_MAIN_MENUS] = {Screen1, Screen2};
    
    int main()
    {
        printf("%s\n", lvl_1[0].value);
    }
    $ gcc bar.c
    $ ./a.out 
    GPS
    $ gcc -std=c89 -ansi -pedantic bar.c
    $ ./a.out 
    GPS
    What compiler are you using?
    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. Coding error?
    By Rush1016 in forum C++ Programming
    Replies: 11
    Last Post: 07-12-2019, 07:32 AM
  2. For loop yields no result(must see)
    By suryap.kv1bbsr in forum C Programming
    Replies: 20
    Last Post: 03-27-2010, 02:10 AM
  3. Using inFile to read from TXT yields gibberish
    By Zzaacchh in forum C++ Programming
    Replies: 4
    Last Post: 08-05-2008, 07:59 PM
  4. Coding Error
    By polonyman in forum C++ Programming
    Replies: 6
    Last Post: 09-10-2004, 02:17 AM
  5. Same seed for srand yields different results
    By codegirl in forum C++ Programming
    Replies: 3
    Last Post: 06-23-2003, 02:39 PM

Tags for this Thread