On 11/16/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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;
}

[EMAIL PROTECTED]/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
[EMAIL PROTECTED]/tmp][11/16/2006 10:33:42][5846]>> c99 testval.c -o testval
[EMAIL PROTECTED]/tmp][11/16/2006 10:33:50][5847]>> ./testval 7
sizeof arx = 7
sizeof arx = 22
sizeof arx = 231
[EMAIL PROTECTED]/tmp][11/16/2006 10:34:02][5848]>>

--Stefan

--
Stefan Teleman
[EMAIL PROTECTED]
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to