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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:57:19+00:00 2026-05-15T12:57:19+00:00

I recently found a interesting behaviour of g++ when compared with MSVC++ 2008. Consider

  • 0

I recently found a interesting behaviour of g++ when compared with MSVC++ 2008. Consider this tiny program:

#include <cstdlib>

const int ARR_LENGTH = 512;

void doSomething( int iLen );

int main( int argc, char** argv )
{
    doSomething( ARR_LENGTH );
    return 0;
}

void doSomething( int iLen )
{
    int iTest[iLen];
    return;
}

Will it compile? What do you think? According to my knowledge of C (or C++ for that matter), this should NOT compile, since i can call the function doSomething() with any integer i want, so the size of iTest array cannot be determined at compile time. However, when i try to compile this with g++, it works just fine. Now i can understand what probably happened here – the compiler noticed that i call this function only once passing a compile-time constant as a parameter. Some serious optimizations going on here… But when i try to compile this using MSVC++ 2008, i get this:

1>c:\prj\test\test.cpp(15) : error C2057: expected constant expression
1>c:\prj\test\test.cpp(15) : error C2466: cannot allocate an array of constant size 0
1>c:\prj\test\test.cpp(15) : error C2133: 'iTest' : unknown size

My question is: how does this comply with the definition of the language (the C standard (C++ standard))? Is it just fine for g++ to do such an optimization (which in this case is easy to see, but the first time i encountered it, it was in a large project and it did not make much sense at first sight).

  • 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-15T12:57:20+00:00Added an answer on May 15, 2026 at 12:57 pm

    C99 (the most recent version of the C standard) does allow dynamically sized arrays.
    However, the feature is not supported by Visual Studio (which only implements C89 support)

    In C++ it is not, and probably will never be, valid.

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

Sidebar

Related Questions

I recently found out about livecoding where someone will program something on the fly
I recently found an interesting issue. When using SetEnvironmentVariable, I can use Process Explorer
So, i recently found this term related somehow to neural networks, but I don't
Recently, I found an interesting Wiki/CMS/Database hybrid called Wagn, where the most important unit
So, I recently found this little gem. http://support.microsoft.com/kb/323308 Essentially, IE doesn't haven't Cache-Control: no-cache
Recently scalaz caught my eye. It looks very interesting, but I have not found
I recently found a log statement in my projects codebase that says here i
I recently found LINQ and love it. I find lots of occasions where use
I've recently found out about protocol buffers and was wondering if they could be
I only recently found out about URL rewriting , so I've still got a

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.