What's the difference in the C vs. the C++ spec that makes it a VLA in GNU-C?

On Fri, Nov 15, 2013 at 10:07 AM, Andrew Pinski <pins...@gmail.com> wrote:
> On Fri, Nov 15, 2013 at 9:31 AM, Hendrik Greving
> <hendrik.greving.in...@gmail.com> wrote:
>> In the below test case, "CASE_A" actually uses a frame pointer, while
>> !CASE_A doesn't. I can't imagine this is a feature, this is a bug,
>> isn't it? Is there any reason the compiler couldn't know that
>> loop_blocks never needs a dynamic stack size?
>
>
> Both a feature and a bug.  In the CASE_A case (with GNU C) it is a VLA
> while in the !CASE_A case (or in either case with C++), it is a normal
> array definition.  The compiler could have converted the VLA to a
> normal array but does not depending on the size of the array.
>
> Thanks,
> Andrew Pinski
>
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> #define MY_DEFINE 100
>> #define CASE_A 1
>>
>> extern init(int (*a)[]);
>>
>> int
>> foo()
>> {
>> #if CASE_A
>>     const int max = MY_DEFINE * 2;
>>     int loop_blocks[max];
>> #else
>>     int loop_blocks[MY_DEFINE * 2];
>> #endif
>>     init(&loop_blocks);
>>     return loop_blocks[5];
>> }
>>
>> int
>> main()
>> {
>>     int i = foo();
>>     printf("is is %d\n", i);
>> }
>>
>> Thanks,
>> Hendrik Greving

Reply via email to