Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 715917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:14:26+00:00 2026-05-14T05:14:26+00:00

I am getting an error message expression must have constant value when initializing an

  • 0

I am getting an error message “expression must have constant value” when initializing an array of structures with an external constant integer.

File1.c:

const unsigned char data1[] =
{
    0x65, 0xF0, 0xA8, 0x5F, 0x5F,
    0x5F, 0x5F, 0x31, 0x32, 0x2E,
    0x31, 0xF1, 0x63, 0x4D, 0x43, 
    0x52, 0x45, 0x41, 0x54, 0x45,
    0x44, 0x20, 0x42, 0x59, 0x3A,
    0x20, 0x69, 0x73, 0x70, 0x56, 
// ...
};
const unsigned int data1_size = sizeof(data1);

File2.c:

const unsigned char data2[] =
{
    0x20, 0x44, 0x61, 0x74, 0x61,
    0x20, 0x52, 0x6F, 0x77, 0x20,
    0x3D, 0x20, 0x34, 0x38, 0x12, 
//...
};
const unsigned int data2_size = sizeof(data2);

Get_Byte.c:

extern const unsigned char * data1;
extern const unsigned int    data1_size;
extern const unsigned char * data2;
extern const unsigned int    data2_size;

struct Array_Attributes
{
    const unsigned char *    p_data;
    const unsigned int       size;
};

const struct Array_Attributes Data_Arrays[] =
{
    {data1, data1_size},  // Error message is for data1_size here.
    {data2, data2_size},  // Another error message generated for data2_size here.
};

I have also removed the const qualifier from the size field of Array_Attributes and get the same error message.

Why is the compiler complaining about a constant value expression when data1_size and data2_size are const unsigned int but in a different translation unit?

I want a constant array of [array address, array size] which is generated at compile time.

I am using Green Hills ccarm 4.24, on Windows XP, C language NOT C++.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:14:27+00:00Added an answer on May 14, 2026 at 5:14 am

    C’s const qualifier has little to do with what the compiler considers a constant expression, in this case. In an initializer, ie

    const struct attributes attrs[] = {
        { expr1, expr2 }, 
        ...
    }
    

    expr1 and expr2 must have very specific forms to be acceptable to the compiler. The upshot of these restrictions is that the expressions can be evaluated without fetching from program variables, since these aren’t in existence at compilation.

    You’re attempting to use data1_size and data2_size, which are not compile time constants by these rules.

    By the way, the declarations

    const unsigned char data1[] = { ... };
    

    and

    extern const unsigned char *data1;
    

    are not compatible and will lead to a bug in your code. The latter should be

    extern const unsigned char data1[];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting an error message in Eclipse: The type of the expression must
I'm getting an error message of ORA-00936: missing expression at the very start of
Getting this error: Each GROUP BY expression must contain at least one column that
I'm getting error messages for no reason in RAD 8: And the error message
Am getting this error message and matched my brackets and couldn't find anything wrong.
Am getting following error message on calling WCF service: The formatter threw an exception
I'm getting this error message whiile running a Webservice I'm working on. it builds,
I'm getting the error message when running the following code from a C# console
I'm getting this error message with the code below: class Money { public: Money(float
I am getting following error message when using Doctrine ORM in Codeigniter. ( !

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.