Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: make the exception example support more than just MSVC

...

Code Block
void addscalar(int n, int m, double a[n][n*m+300], double x);

int main(void)
{
  double b[4][308];
  addscalar(4, 2, b, 2.17);
  return 0;
}

void addscalar(int n, int m, double a[n][n*m+300], double x) 
{
  for (int i = 0; i < n; i++)
  for (int j = 0, k = n*m+300; j < k; j++)
    /* a is a pointer to a VLA with n*m+300 elements */
    a[i][j] += x;
}

...

API05-C-EX0: The extended array syntax is not supported by C++, or platforms that do not support C99, such as MSVC. Consequently, C programs that must support such platforms, including Windows, need not use conformant array parameters. One option for portable code that must support MSVC such platforms is to use macros:

Code Block
bgColor#ccccff
langc
#include <stddef.h>
  
#if !defined(__STDC_VERSION__) || defined(__STDC_NO_VLA_MSC_VER)
  #define N(x)
#else
  #define N(x)  (x)
#endif
  
int f(size_t n, int a[N(n)]);

...