Hi,
On Mon, 23 Oct 2006, David A. Case wrote:
> On Mon, Oct 23, 2006, Scott Brozell wrote:
>
> > The larger issue is the merit of picking c89 vs c99, and enforcing that by
> > using for example gcc -std=c89. As for fortran 95 the advantage of
> > compiler getting feedback about nonstandard language constructs is that
> > we can keep them out of the sources and avoid this platform specific
> > nuisance.
>
> Do you know if sgi mips compilers will accept variable length arrays in C?
> To me, that seems like one of the most useful C99 extensions, since you can
> effectively have temporary arrays without a malloc/free logic around it.
> However, I don't think that anyone has used this feature yet in the Amber
> code.
Yes, variable length arrays are accepted.
Oct 31 12:23:23pm pusar 636> ~/lang cc -version
MIPSpro Compilers: Version 7.3.1.2m
Oct 31 12:23:25pm pusar 637> ~/lang cc vararray.c
Oct 31 12:23:29pm pusar 638> ~/lang cc -ansi -pedantic vararray.c
cc-1385 cc: ERROR File = vararray.c, Line = 7
A parameter is not allowed.
int PrintArray(int d2, int a[][d2][DIM3], int dim1)
^
cc-1028 cc: ERROR File = vararray.c, Line = 7
The expression used must have a constant value.
int PrintArray(int d2, int a[][d2][DIM3], int dim1)
^
cc-1028 cc: ERROR File = vararray.c, Line = 26
The expression used must have a constant value.
int a[D1][DI2][DIM3];
^
cc-1028 cc: ERROR File = vararray.c, Line = 26
The expression used must have a constant value.
int a[D1][DI2][DIM3];
^
cc-1028 cc: ERROR File = vararray.c, Line = 26
The expression used must have a constant value.
int a[D1][DI2][DIM3];
^
5 errors detected in the compilation of "vararray.c".
Oct 31 12:24:47pm pusar 642> ~/lang cat vararray.c
/* exercise variable length arrays in C99 */
#include <stdio.h>
const int DIM3 = 3;
int PrintArray(int d2, int a[][d2][DIM3], int dim1)
{
int i = 0;
for (i = 0; i < dim1; ++i) {
int j = 0;
for (j = 0; j < d2; ++j) {
int k = 0;
for (k = 0; k < DIM3; ++k) {
printf("a[%d][%d][%d] = %3d\n", i, j, k, a[i][j][k]);
}
}
}
return 0;
}
int main(int argc, char *argv[])
{
static const int D1 = 5;
const int DI2 = 2;
int a[D1][DI2][DIM3];
int i = 0;
for (i = 0; i < D1; ++i) {
int j = 0;
for (j = 0; j < DI2; ++j) {
int k = 0;
for (k = 0; k < DIM3; ++k) {
a[i][j][k] = 100 * i + 10 * j + k;
printf("A[%d][%d][%d] = %3d\n", i, j, k, a[i][j][k]);
}
}
}
putchar('\n');
PrintArray(DI2, a, D1);
return 0;
}
Received on Wed Nov 01 2006 - 06:07:32 PST