This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Using `const int' values to size stack arrays


Hi all,

If I have a variable which I declare in one of the following ways:

const int MAX_VAL = 12;

or

static const int MAX_VAL = 12;

and I subsequently use it in expressions, gcc will substitute the value `12' wherever MAX_VAL appears, but not in the following case:

void someFn()
{
int someArray[MAX_VAL];

 // etc...
}

In this case, `someArray' will be treated as a variable sized array, with subsequent performance impact. Why can't gcc treat it as an array which has 12 elements? Is this a gcc limitation, or a fundamental limitation of C?

thanks,

dan.

============================================================================
Daniel Towner
picoChip Designs Ltd., Riverside Buildings, 108, Walcot Street, BATH,
BA1 5BG
daniel.towner@picochip.com
07786 702589




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]