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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:20:53+00:00 2026-06-01T19:20:53+00:00

I’ve looked at these and they do not answer my question: variable-sized object may

  • 0

I’ve looked at these and they do not answer my question:

variable-sized object may not be initialized

C compile error: "Variable-sized object may not be initialized"

Error: Variable-sized object may not be initialized. But why?

I am trying to write some fairly portable c code:

int main () 
{
    const int foo=13;
    int bar[foo]={0};
    return 0;
}

I get a `variable-sized object may not be initialized` error when compiling as `c` code using either:

  • gcc 4.3.4
  • arm-linux-gnueabi-gcc 4.4.5

And if i compile it as c in VS2008 i get a slightly different error C2057: expected constant expression

I understand that here, the c code compiler is not recognising const int foo=13; to be truly constant; for example we might have

void a(int fool) 
{    
    const int foo=fool;
    int bar[foo]={0};
}

I also realise that unlike the gcc compilers, the VS2008 compiler has no concept of C99 variable-length arrays. And that MS apparently has not mentioned any future support.

And yet, cpp code compilation with either gcc or MS compilers is altogether different/cleverer ?!

  • this fails to compile
  • but this will compile

And also *what i do not understand* regarding the **gcc** `c` code compiler is:

  • since this code does compile,
int main () 
{
    int bar[13]={0};
    return 0;
}
  • why this code does not compile..
int main()
{
    const int foo=13; //cpp compiler knows this really is const ! 
    int bar[foo]={0};
    return 0;
}
  • and yet this code does compile?
int main()
{
    const int foo=13;  
    int bar[foo+1]={0}; //wtF?
    return 0;
}

(NB: in this last case, MS c code compilation fails; consistently as with int bar[foo]={0};)

  • 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-01T19:20:54+00:00Added an answer on June 1, 2026 at 7:20 pm

    C99 §6.7.8 Initialization says this:

    The type of the entity to be initialized shall be an array of unknown size or an object type that is not a variable length array type.

    So your initialization is invalid C.

    The only way for type a[size] to not be a VLA is for size to be an integer constant expression (§6.7.5.2). What you have there is not an integer constant expression, so you have a VLA:

    If the size is not present, the array type is an incomplete type. If the size is * instead of being an expression, the array type is a variable length array type of unspecified size,
    which can only be used in declarations with function prototype scope such arrays are
    nonetheless complete types. If the size is an integer constant expression and the element type has a known constant size, the array type is not a variable length array type;
    otherwise, the array type is a variable length array type.

    Part §6.6/6 Constant expressions defines them as:

    An integer constant expression shall have integer type and shall only have operands
    that are integer constants, enumeration constants, character constants, sizeof
    expressions whose results are integer constants, and floating constants that are the
    immediate operands of casts. Cast operators in an integer constant expression shall only
    convert arithmetic types to integer types, except as part of an operand to the sizeof
    operator.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I need a function that will clean a strings' special characters. I do NOT
I am using Paperclip to handle profile photo uploads in my app. They upload
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.