ms-extensions标志对gcc有什么作用? [英] What does the ms-extensions flag do exactly with gcc?

查看:513
本文介绍了ms-extensions标志对gcc有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC具有标志-fms-extensions.

此标志的作用是什么?为什么有时默认情况下启用它,为什么它存在?

What does this flag do exactly? Why is it sometimes on by default, and why does it exist?

推荐答案

根据gcc 9.1.0源代码(针对flag_ms_extensions而言),效果是:

According to the gcc 9.1.0 source code (grepped for flag_ms_extensions) the effects are:

  • (C)允许匿名联合和结构.这些已添加到C11标准中,但即使在较旧的模式下(例如C99或Ansi),该标志也将启用它们.
  • (C ++)允许类成员与其类型使用相同的名称(例如using foo = int; struct A { foo foo; }).在禁用ms-extensions的情况下,其行为是在C中接受此代码(在合法的情况下);或extern "C"块,除非给出了-pedantic标志.错误消息是declaration of NAME changes meaning of NAME.
  • (C ++)允许隐式int ;现在允许使用任何可能产生诊断ISO C++ forbids declaration of NAME with no type的情况,并假定类型为int.例如:const *p;const f();.
  • (C ++)允许从命名为非静态成员函数的 qualified-id 隐式转换为指向成员的指针.在ISO C ++中,需要&运算符来执行该转换.
  • (C ++),如果f(一个不合格ID)在该上下文中命名一个未重载的成员函数,则允许&f形成一个指向成员的指针. ISO C ++要求使用类名进行显式限定.
  • (C) Allow anonymous unions and structs. These were added to the C11 standard, but the flag will enable them even in older modes such as C99 or Ansi.
  • (C++) Allow a class member to have the same name as its type (e.g. using foo = int; struct A { foo foo; }). With ms-extensions disabled, the behaviour is to accept this code in C (where it is legal); or an extern "C" block unless -pedantic flag was given. The error message for this is declaration of NAME changes meaning of NAME.
  • (C++) Allow implicit int; any situation that would have produced the diagnostic ISO C++ forbids declaration of NAME with no type is now allowed, with int assumed as the type. Examples: const *p; or const f();.
  • (C++) Allow implicit conversion from a qualified-id naming a non-static member function, to a pointer-to-member. In ISO C++ the & operator is required to perform that conversion.
  • (C++) Allow &f to form a pointer-to-member, if f (an unqualified-id) names a non-overloaded member function in that context. ISO C++ requires explicit qualification with the class name.

如果目标ABI是Microsoft ABI,则默认情况下该标志为打开状态.可以通过手动指定-fno-ms-extensions来禁用它.

The flag is turned on by default if the Target ABI is a Microsoft ABI. It can be disabled by manually specifying -fno-ms-extensions.

背后的理由是一个更棘手的问题. 文档 必须说:

The rationale behind this is a tougher question. The documentation has to say:

接受Microsoft头文件中使用的一些非标准构造.

Accept some non-standard constructs used in Microsoft header files.

禁用有关MFC中使用的构造的Wpedantic警告.

Disable Wpedantic warnings about constructs used in MFC.

因此,我认为基本原理是允许g ++构建依赖MSVC供应商中非标准代码的 MFC 应用程序-提供的标题.

So I assume the rationale is to allow g++ to build MFC applications which depend on non-standard code in MSVC vendor-supplied headers.

我不确定在2019年这仍然有多重要,我认为gcc可以默认关闭此标志是一个很好的例子. (如果用户要构建旧的MFC应用程序,则始终可以指定它).

I am not sure how relevant that still is in 2019 and I think a good case could be made for gcc to default to having this flag turned off. (Users can always specify it if they want to build an old MFC app).

例如,MSVC 19.xx(最新版本)在其默认模式下不再允许最后三个项目符号. (即使使用/Za标志,它仍然允许foo foo;.)

For example MSVC 19.xx (the latest version to date) no longer allows the last three bullet points in its default mode. (It does still allow foo foo; even with /Za flag).

这篇关于ms-extensions标志对gcc有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆