I ran into this the other day as well. I noticed it would never compile on VC++ but it will on GCC and I couldn't figure out if VC++ was stupid or if GCC was stupid. So could someone clarify this: By the C++ standard which also should be the same with the C standard, is it correct to allocate an array when it's size is based on a non-constant variable? And if not, what is the most appropriate way to fix this?
Neither GCC nor VC++ are being stupid. This is what's called a language extension. You can use them or or ignore them, but you should at least know that they are extensions so that you can avoid them when necessary.
As for how to do this the portably, the answer is a few posts back.