Thread: error: initializer element is not constant

  1. #1
    Registered User
    Join Date
    Jun 2019
    Posts
    3

    error: initializer element is not constant

    I am working on a c program where the .c file does not have a main function. It has an array
    Code:
    static const uint8_t adData1[5] = {
            /* Major Version */    0x00, 0x01,
            /* Minor Version */    0x00, 0x01,
                                   0xC5};
    I wanted to replace the "minor version" value ( 0x00, 0x01) by a dynamic value, lets say dynamic_value.

    When I tried to add this dynamic_value inside the array, it throws mean an error such that " error: initializer element is not constant" . Any other ways to overcome this?
    Regadrs
    Niranjan

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,013
    Before adData1 is ever accessed, assign dynamic_value to the desired elements of the array. Where exactly that is depends on the details of the implementation since as you say, there is no main function hence this is presumably a freestanding environment, so you would place that code in the relevant startup function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    112
    dynamic value
    const = constant: adjective. not changing or varying;


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. initializer element is not constant
    By Athul in forum C Programming
    Replies: 6
    Last Post: 10-22-2018, 09:05 AM
  2. "initializer element is not constant" error
    By dukester in forum C Programming
    Replies: 24
    Last Post: 05-18-2011, 12:03 PM
  3. initializer element is not constant error - help
    By jay32m in forum C Programming
    Replies: 7
    Last Post: 11-17-2010, 03:24 PM
  4. initializer element is not constant...
    By John Connor in forum C Programming
    Replies: 12
    Last Post: 02-01-2008, 06:28 PM
  5. initializer element is not constant
    By lucaspewkas in forum C Programming
    Replies: 4
    Last Post: 05-20-2005, 05:21 AM

Tags for this Thread