<p>I have a simple function in which an array is declared with size
depending on the parameter which is int.</p>

<pre><code>    void f(int n){
        char a[n];
    };

    int main() {
        return 0;
    }
</code></pre>

<p>This piece of code compiles fine on <a href="http://en.wikipedia.org/wiki/G%2B%2B" rel="noreferrer">GNU C++</a>, but not on MSVC 2005.</p>

<p>I get the following compilation errors:</p>

<pre><code>    .\main.cpp(4) : error C2057: expected constant expression
    .\main.cpp(4) : error C2466: cannot allocate an array of constant size 0
    .\main.cpp(4) : error C2133: 'a' : unknown size
</code></pre>

<p>What can I do to correct this?</p>

<p>(I'm interested in making this work with MSVC,without using new/delete)</p>

Your method of allocating from the stack is a g++ extension. To do the equivalent under MSVC, you need to use _alloca:
```
```
char *a = (char *)_alloca(n);
```
```