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 8613655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:56:07+00:00 2026-06-12T04:56:07+00:00

So in my source file I have the folowin function: void update(state* old_state, state*

  • 0

So in my source file I have the folowin function:

void update(state* old_state, state* measurement, uint32_t size)
{
  state new_state[size];
  //some function using measurement and old_state and returning the result in newstate

  arm_fadd_32(measurement,old_state,newstate,size);

// rest of the code
}

Now the compiler throws an error saying that
error#28:expression must have a constant value.
I think it’s due to the fact that even though inside the method the size local variable is not changing the compiler is expecting a constant while defining the size.
I have tried the following:

int const a = size; 

and then tried to reinitialize it says constant value is not known.
I did some research in internet and it appears that there is no easier way without using malloc, which I don’t want to since I am using the code for some embedded application.

Is there a way to avoid this problem without really using malloc? Thanks in advance guys!

  • 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-06-12T04:56:09+00:00Added an answer on June 12, 2026 at 4:56 am

    As of the 1990 ISO C standard, the size of an array must be a constant integer expression. Note “constant”, not const. A constant expression is (roughly) one whose value is known at compile time; const, though it comes from the same root word, really just means “read-only”.

    The 1999 standard added VLAs (variable length arrays), which would make your code legal. One drawback of VLAs is that there’s no mechanism to detect a failure to allocate the required space; if the allocation fails, your programs behavior is undefined. (It may crash if you’re lucky.)

    Most C compilers these days do support most of the C99 standard; you may need a command-line option to enable it. Microsoft’s C compiler, on the other hand, supports only C90, plus a very few C99-specific features, and Microsoft has stated that they have no plans to change that. If you’ll lets us know what compiler you’re using, we can probably be more helpful.

    You can use malloc() to allocate a dynamically sized array on the heap:

    state *new_state = malloc(size * sizeof *new_state);
    if (new_state == NULL) {
        // allocation failed, handle the error somehow
    }
    

    Note that malloc() returns a null pointer to indicate an allocation failure, which is an advantage over VLAs even if your compiler supports them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a source file that I can run via the terminal using gcc
Suppose I have a source file open and I launch a shell. I can
Suppose I have a source file that is 18218 bytes. I open the file
I have a source file, openpage.pl, where I call use_module/1 to import SWI-Prolog's http_open/3:
I have a source file where 2 features have been added. In order to
I have a large source file in Perforce that has been split up into
I have a c source file in which one of the method is defined
Suppose I have two lists that holds the list of source file names and
Referring here A is a precompiled Java class (I also have the source file)
I am running Cygwin Python version 2.5.2. I have a three-line source file, called

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.