Which compiler should I trust?

前端 未结 4 1185
情话喂你
情话喂你 2020-11-28 00:00

This is going to be some what of a newbie question but I was trying to work on a small exercise in the C Language (not C++) and I was running into some iss

4条回答
  •  借酒劲吻你
    2020-11-28 00:23

    It depends upon the particular standard your C compiler is following.

    The feature you want is called variable length array (VLA) and was introduced into the C99 standard.

    Maybe your Visual Studio is supporting some earlier version of the standard. Perhaps you might configure it to support a later version.

    Notice that using VLA with a huge size could be a bad habit: VLA are generally stack allocated, and a call frame stack should usually have a small size (a few kilobytes at most on current processors), especially for kernel code or for recursive or multithreaded functions. You may want to heap-allocate (e.g. with calloc) your array if it is has more than a thousand words. Then you'll need to free it later.

提交回复
热议问题