2

我正在寻找一组's 来检查GCC 和 Visual Studio#ifdef的关键字的可用性。__restrict我假设它需要检查编译器版本,但我不知道它是针对哪个版本引入的。任何人都可以帮助我吗?

更新:当编译为 C89 时,这必须(并且只需要)工作!所以我不能指望__STDC_VERSION__C99 或 C99 支持。

4

4 回答 4

1

只需使用 C99 标准关键字restrict,也可能使用#define其他关键字。

您可以测试 C99 的一致性,例如:

#if __STDC__ != 1
#    error not conforming
#    define restrict __restrict /* use implementation __ format */
#else
#    ifndef __STDC_VERSION__
#        error not conforming
#        define restrict __restrict /* use implementation __ format */
#    else
#        if __STDC_VERSION__ < 199901L
#            error Compiler for C before C99
#            define restrict __restrict /* use implementation __ format */
#        else
#            /* all ok */
#        endif
#    endif
#endif

int fx(int *restrict a, char *restrict b) {
  *b = *a;
  return 0;
}

int main(void) {
  int a[1];
  char b[1];
  fx(a, b);
  return 0;
}

当然#errors 应该在工作版本中被编辑掉

于 2011-05-10T09:05:40.367 回答
1

在“配置、制作、安装”场景中,应在“配置”中检查。'configure' 应该在 config.h 中定义一个 'HAS_RESTRICT'。这应该反过来在您的标题中检查以定义合适的宏。

对于视觉工作室,我的想法为零.. :(

于 2011-05-10T09:08:01.477 回答
1

我如何修复它:

#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
#   define SKP_restrict __restrict
#elif defined(_MSC_VER) && _MSC_VER >= 1400
#   define SKP_restrict __restrict
#else
#   define SKP_restrict
#endif
于 2011-05-10T09:38:54.130 回答
0

恕我直言,__restrict这两个 C/C++ 程序的所有标准编译器都应该可用。C99 restrict它在某些方面类似于。

于 2011-05-10T09:05:09.563 回答