On 11/16/06, Casper.Dik at sun.com <Casper.Dik at sun.com> wrote:
>
> >Because argc is not an "integer constant expression". :-)
>
> We're talking about "variable length arrays"; clearly C++ does
> not support them.
>
> const int foo = X;
>
> is just a glorified #define giving you fixed size arrays.


#include <stdio.h>
#include <stdlib.h>

void foo(int x)
{
    char arx[x];
    (void) fprintf(stderr, "sizeof arx = %u\n", sizeof(arx));
}

int
main(int argc, char* argv[])
{
    int sz;
    if (argc != 2)
    {
        (void) fprintf(stderr, "nope\n");
        return 1;
    }

    sz = atoi(argv[1]);

    foo(sz);
    foo(sz + 15);
    foo(sz * 33);
    return 0;
}

[steleman at redneck][~/tmp][11/16/2006 10:33:34][5845]>> c89 testval.c -o 
testval
"testval.c", line 6: integral constant expression expected
c89: acomp failed for testval.c
[steleman at redneck][~/tmp][11/16/2006 10:33:42][5846]>> c99 testval.c -o 
testval
[steleman at redneck][~/tmp][11/16/2006 10:33:50][5847]>> ./testval 7
sizeof arx = 7
sizeof arx = 22
sizeof arx = 231
[steleman at redneck][~/tmp][11/16/2006 10:34:02][5848]>>

--Stefan

-- 
Stefan Teleman
stefan.teleman at gmail.com

Reply via email to