Sizing a (stack based) array at run time
I'm converting some code that was originally written for the gcc compiler. It has a couple of functions that look like this:-
Code:
void the_function (size_t buf_size)
{
float buffer[buf_size];
// Rest of function
}
VC++ doesn't like this (it needs a compile time constant for the buffer size). In fact, I'm a bit surprised that gcc accepts it, but no matter.
I realise I could just make the buffer heap based - but back in the days when I was using Borland C, there was a technique for getting around this problem by using a multidimensional array. Borland's compiler could accept a run time variable as the first size in a multidimensional array - so you could do something like this:-
Code:
float buffer[buf_size][1];
Does VC++ have any similar kludge?
"A problem well stated is a problem half solved.” - Charles F. Kettering