Search code examples
carraysgcckeiliar

Array size defined in a Variable in C cannot compile in IAR but builds fine in Keil


#include<stdio.h>
int main()
{
     int x = 5;
     int length = 5+x;
     int arrayw[length];


        return 0;
}

This code builds fine in gcc and Keil but not in IAR.

I get this error : 
Error[Pe028]: expression must have a constant value 

How can it be made to compile fine in IAR toolchain


Solution

  • Follow this: https://netstorage.iar.com/SuppDB/Public/UPDINFO/013556/ew/doc/infocenter/GettingStarted/CreatingAnApplicationProject/CreatingAnApplProj.ENU.html

    On the step where it says Setting project options make sure to select C99.

    Here is the window you're looking for:

    enter image description here

    P.S. There is also an option to explicitly allow VLA in IAR. See http://www.keil.com/support/man/docs/armcc/armcc_chr1359124950297.htm