Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the warning " ISO C90 forbids variable-size array" in gcc compiler while compiling C90 code

I am compiling my C90 c code in gcc . I am getting the warningISO C90 forbids variable-size array while making the declaration like

int symbols[nc];

Where nc is integer whose value is read from the input file. The values on the input files are varied so i can't keep a constant value. How can I get rid of it? Is it indeed necessary to resolve this warning or we can simply ignore it?

Thanks in advance.

like image 206
thetna Avatar asked May 30 '26 08:05

thetna


1 Answers

You get that warning because C90 does not support variable length arrays.

You'll either have to switch gcc to C99 mode (which does support vla) , by using the -std=c99 or std=gnu99 command line flag, or rewrite your code to dynamically allocate memory or use a fixed size array.

The warning just tells you that you're not conforming to C90 in this case, but it's otherwise safe. Ignoring a warning should really not be an option though.

like image 67
nos Avatar answered Jun 01 '26 02:06

nos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!