Home > Back-end >  What are the compiler support variable-length array?
What are the compiler support variable-length array?

Time:06-03

Now a beginner, with the DEV c + +, now find cannot compile variable-length arrays, each elder have longer to compile an array with the recommendation of a compiler

CodePudding user response:

If you have a variable-length array (VLA) is, so dev is supported by the c + +; If you require a compiler, you can choose the GCC or TCC,

CodePudding user response:

reference 1st floor apkipa1 response:
if you have a variable-length array (VLA) is, so dev is supported by the c + +; If you require a compiler, you can choose the GCC or TCC,

VLA, DEV out
Refer to the program in listing 10.18
//program listing 10.18 - the use of variable-length array function
#include
# define ROWS 3
# define COLS 4
Int sum2d (int rows, int cols, int ar [rows] [cols]);
Int main (void)
{
int i,j;
Int the rs=3;
Int cs=10;
Int junk [ROWS] [COLS]={
,4,6,8 {2},
,4,7,9 {3},
,10,8,6 {12}
};

Int morejunk [ROWS 1] [COLS + 2]={
20,30,40,50,60,70 {},
{5,6,7,8,9,10}
};

Int varr [rs] (cs);//variable-length array

for(i=0; ifor(j=0; jVarr [I] [j]=I * j + j;

Printf (" 3 x5 array \ n ");
Printf (" the Sum of all elements=% d \ n ",
Sum2d (ROWS, COLS, junk));

Printf (" 2 x6 array \ n ");
Printf (" the Sum of all elements=% d \ n ",
Sum2d (ROWS 1, COLS + 2, morejunk));

Printf (" 3 x10 VLA \ n ");
Printf (" the sum of all elements=% d \ n ",
Sum2d (rs and cs, varr));

return 0;
}

//with a VAL parameter function
Int sum2d (int rows, int cols, int ar [rows] [cols])
{
Int r;
Int c;
Int tot=0;

For (r=0; R=rows; R++)
For (c=0; CTot +=ar [r] [c];
Return tot.

}

You try

CodePudding user response:

Commonly used in compiler CL except Microsoft support

CodePudding user response:

I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related