The following code has a different macro expansion for MSVC
and GCC
compiler:
#include <array>
#include <iostream>
#define UNROLL_REPEAT_I_1(X, ...) X(0, ##__VA_ARGS__)
#define UNROLL_REPEAT_I_2(X, ...) \
UNROLL_REPEAT_I_1(X, ##__VA_ARGS__) X(1, ##__VA_ARGS__)
#define UNROLL_REPEAT_I_3(X, ...) \
UNROLL_REPEAT_I_2(X, ##__VA_ARGS__) X(2, ##__VA_ARGS__)
#define BLAS_1V_IT(I, X0, Op0) (X0[I]) Op0
#define BLAS_UNROLL_IT(K, X, ...) X(blas_index + K, ##__VA_ARGS__);
int
main()
{
double x[10], a;
int blas_index = 0;
UNROLL_REPEAT_I_3(BLAS_UNROLL_IT, BLAS_1V_IT, x, = a);
return 0;
}
For GCC
compiler, expansion of UNROLL_REPEAT_I_3
in main function is what I want:
(x[blas_index + 0]) = a; (x[blas_index + 1]) = a; (x[blas_index + 2]) = a;
However, for MSVC
compiler, the result is weird and cannot be compiled successfully:
BLAS 1V IT, x, = a(blas index + 0 ); (x, = a[blas index + 1]) ; (x[blas index + 2]) = a;
Is there any feasible modification for this code to make sure it has same expansion by both of the MSVC
and GCC
compiler?