GCC二进制文字和C ++ 14之间的区别?

时间:2021-07-08 16:38:49

C++14 seems to be coming and compilers are already trying to implement the core features of this new revision. I was having a look at GCC support for these core features and noticed something about the binary literals part: GCC implements them but seems to make a difference between GNU binary literals and C++14 binary literals. Here are the respective references for both:

C ++ 14似乎即将到来,编译器已经在尝试实现这个新版本的核心功能。我正在研究GCC对这些核心功能的支持,并注意到二进制文字部分:GCC实现了它们,但似乎在GNU二进制文字和C ++ 14二进制文字之间有所区别。以下是两者的相应参考:

I tried to find some differences between the two of them since GCC seems to make the difference, but could not find anything. Does any of you know more about possible incompatibilities?

我试图找到他们两个之间的一些差异,因为GCC似乎有所作为,但找不到任何东西。你们中有谁知道更多可能的不兼容性吗?

3 个解决方案

#1


20  

From the commit diff which introduced support in gcc 4.9, the only difference is that gcc now accepts binary literals as a language feature of C++1y, and doesn't warn that they're a gcc extension if C++1y support is specified. There is no change to the actual implementation.

从在gcc 4.9中引入支持的commit diff,唯一的区别是gcc现在接受二进制文字作为C ++ 1y的语言特性,并且如果C ++ 1y支持则不警告它们是gcc扩展名。指定。实际实施没有变化。

Previously:

warning : binary constants are a GCC extension

Now, unless -std=c++1y is specified:

现在,除非指定了-std = c ++ 1y:

warning : binary constants are a C..1y feature or GCC extension

#2


3  

I'm guessing that the difference is since one is an extension, then people wouldn't be too inclined to use it while the other is standard compliant and accessible without turning on extensions. It's a formality.

我猜测差异是因为一个是扩展,然后人们不会太倾向于使用它,而另一个是标准兼容的,无需启用扩展即可访问。这是一种形式。

#3


0  

The first document you point to is the GNU implementation of binary literals as an extension to the C language (ie, it is a non-standard feature of C and that document defines how gcc implements an extension to the language).

您指向的第一个文档是二进制文字的GNU实现,作为C语言的扩展(即,它是C的非标准特性,该文档定义了gcc如何实现语言的扩展)。

The second document you point to is a proposal to add binary literals to the C++11 language, but as far as I know it has not been accepted either (*) and that means it's not part of standard C++ either, it remains as a language extension provided by gcc.

您指向的第二个文档是将二进制文字添加到C ++ 11语言的提议,但据我所知,它也未被接受(*),这意味着它也不是标准C ++的一部分,它仍然是gcc提供的语言扩展。

As far as I can see this feature would be non-portable across compilers, but you could define your own binary literal implementation in C++11 by using user defined literals.

据我所知,这个功能在编译器中是不可移植的,但您可以使用用户定义的文字在C ++ 11中定义自己的二进制文字实现。

(*) s/not accepted/I can't find any reference to binary literals in N3485 "Working Draft, Standard for Programming Language C++", but it might be a feature accepted for the next standard of C++.

(*)s /不接受/我在N3485“编程语言C ++标准工作草案”中找不到对二进制文字的任何引用,但它可能是下一个C ++标准所接受的特性。

#1


20  

From the commit diff which introduced support in gcc 4.9, the only difference is that gcc now accepts binary literals as a language feature of C++1y, and doesn't warn that they're a gcc extension if C++1y support is specified. There is no change to the actual implementation.

从在gcc 4.9中引入支持的commit diff,唯一的区别是gcc现在接受二进制文字作为C ++ 1y的语言特性,并且如果C ++ 1y支持则不警告它们是gcc扩展名。指定。实际实施没有变化。

Previously:

warning : binary constants are a GCC extension

Now, unless -std=c++1y is specified:

现在,除非指定了-std = c ++ 1y:

warning : binary constants are a C..1y feature or GCC extension

#2


3  

I'm guessing that the difference is since one is an extension, then people wouldn't be too inclined to use it while the other is standard compliant and accessible without turning on extensions. It's a formality.

我猜测差异是因为一个是扩展,然后人们不会太倾向于使用它,而另一个是标准兼容的,无需启用扩展即可访问。这是一种形式。

#3


0  

The first document you point to is the GNU implementation of binary literals as an extension to the C language (ie, it is a non-standard feature of C and that document defines how gcc implements an extension to the language).

您指向的第一个文档是二进制文字的GNU实现,作为C语言的扩展(即,它是C的非标准特性,该文档定义了gcc如何实现语言的扩展)。

The second document you point to is a proposal to add binary literals to the C++11 language, but as far as I know it has not been accepted either (*) and that means it's not part of standard C++ either, it remains as a language extension provided by gcc.

您指向的第二个文档是将二进制文字添加到C ++ 11语言的提议,但据我所知,它也未被接受(*),这意味着它也不是标准C ++的一部分,它仍然是gcc提供的语言扩展。

As far as I can see this feature would be non-portable across compilers, but you could define your own binary literal implementation in C++11 by using user defined literals.

据我所知,这个功能在编译器中是不可移植的,但您可以使用用户定义的文字在C ++ 11中定义自己的二进制文字实现。

(*) s/not accepted/I can't find any reference to binary literals in N3485 "Working Draft, Standard for Programming Language C++", but it might be a feature accepted for the next standard of C++.

(*)s /不接受/我在N3485“编程语言C ++标准工作草案”中找不到对二进制文字的任何引用,但它可能是下一个C ++标准所接受的特性。