This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Using `const int' values to size stack arrays
- From: Daniel Towner <daniel dot towner at picochip dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 17 Nov 2004 10:28:19 +0000
- Subject: 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