gcc - '-std' 和 '--std' 编译器标志之间的差异

标签 gcc compiler-flags

我注意到 -std--std 都可以用于设置编译标准。在 std 之前使用 --- 有什么区别?

我用谷歌搜索发现this ,但它似乎没有提及有关 std 之前的单个连字符与双连字符的任何信息。

最佳答案

-std=c99 没问题,但 -std c99 是错误。 --std c99--std=c99 一样有效。这是唯一的区别。

您可以看到它们映射到 opts-common.c 中的相同操作:

struct option_map
{
  /* Prefix of the option on the command line.  */
  const char *opt0;
  /* If two argv elements are considered to be merged into one option,
     prefix for the second element, otherwise NULL.  */
  const char *opt1;
  /* The new prefix to map to.  */
  const char *new_prefix;
  /* Whether at least one character is needed following opt1 or opt0
     for this mapping to be used.  (--optimize= is valid for -O, but
     --warn- is not valid for -W.)  */
  bool another_char_needed;
  /* Whether the original option is a negated form of the option
     resulting from this map.  */
  bool negated;
};

static const struct option_map option_map[] =
  {
   ...
    { "--std=", NULL, "-std=", false, false },
    { "--std", "", "-std=", false, false },
   ...
  };

关于gcc - '-std' 和 '--std' 编译器标志之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35241521/

相关文章:

c++ - 使用 cmake 有条件地生成源输入文件

c++ - 奇怪的枚举名称冲突

c++ - GCC 警告 [未初始化]

c++ - 将 'const' 作为 'this' 参数传递时出错

c++ - 基于 GCC 构建的 Clang

c - 为什么在尝试将数组从标准输入复制到二维数组时出现段错误?

c++ - 试图修复转换警告

c++ - 如何在 C++ 文件中的 #ifdef 中使用 Makefile 中的变量

c++ - #在 Visual C++ 2013 中将实际函数名称定义为 __noop

c++ - cmake 如何在 C++ 中将编译器标志附加到末尾