MSVC与GCC的差异(收集中)
来源:互联网 发布:usb电子显微镜软件app 编辑:程序博客网 时间:2024/04/26 20:07
1. 变长数组的支持.
GCC支持,MSVC不支持
2. 临时变量作为函数参数传递
f(const QString& s);
g(QString& s);
f("abc"); //MSVC通过,GCC不通过
g("abc"); //MSVC和GCC都通过
3. 找不到静态常量的定义, undefined reference to static const variable
enum TypeId {B_TYPE=0, C_TYPE};
class B
{
public:
static const TypeId B_ID=B_TYPE;
};
g((int)B::B_ID); //都工作
g(+B::B_ID); //都工作
g(B::B_ID); //MSVC工作,在GCC下不工作,
//GCC报告链接错误undefined reference to `B::B_ID' 找不到静态常量的定义
这个问题在http://gcc.gnu.org/ml/gcc-bugs/2005-03/msg02430.html 也有说,但GCC似乎不认为这是个bug
http://stackoverflow.com/questions/272900/c-undefined-reference-to-static-class-member 这个地方有个回答,说的比较清楚
The C++ standard requires a definition for your static const member if the definition is somehow needed.
The definition is required, for example if it's address is used. push_back
takes its parameter by const reference, and so strictly the compiler needs the address of your member and you need to define it in the namespace.
When you explicitly cast the constant, you're creating a temporary and it's this temporary which is bound to the reference (under special rules in the standard).
This is a really interesting case, and I actually think it's worth raising an issue so that the std be changed to have the same behaviour for your constant member!
Although, in a weird kind of way this could be seen as a legitimate use of the unary '+' operator. Basically the result of the unary +
is an rvalue and so the rules for binding of rvalues to const references apply and we don't use the address of our static const member:
v.push_back( +Foo::MEMBER );
Yes it's certainly weird that for an object x of type T, the expression "(T) x" can be used to bind a const ref while plain "x" can't. I love your observation about "unary +"! Who would have thought that poor little "unary +" actually had a use... :) – j_random_hacker May 29 '09 at 10:38 Thinking about the general case... Is there any other type of object in C++ that has the property that it (1) can be used as an lvalue only if it has been defined but (2) can be converted to an rvalue without being defined? – j_random_hacker May 29 '09 at 10:51 Good question, and at least at the moment I cannot think of any other examples. This is probably only here because the committee were mostly just reusing existing syntax. – Richard Corden May 29 '09 at 12:47
- MSVC与GCC的差异(收集中)
- 使GCC兼容MSVC的intrin.h
- 代码从GCC到MSVC的移植
- MinGW 与MSVC的区别
- vs2008与gcc在union初始化上的差异
- Oracle收集表的数据与统计信息差异
- C++中如何强制inline函数(MSVC, GCC)
- C代码从GCC到MSVC的移植
- cmake:让mingw(gcc)生成MSVC可用的dll(.lib)
- C代码从GCC到MSVC的移植
- C++字符编码于MSVC和GCC之间的区别
- Qt: MinGW 与MSVC的区别
- Qt编译器--MinGW与MSVC的区别
- Silverlight与WPF中BeginInvoke的差异
- Silverlight与WPF中BeginInvoke的差异
- VHDL中信号与变量的差异
- Silverlight与WPF中BeginInvoke的差异
- mex中如何禁止msvc的warnning
- J2EE项目代码编写规范
- 一些軟件分析和設計方面的書
- PHP查询显示SqlServer中的中文
- 找第K大数的一些小算法技巧;
- java 正则表达式工具类
- MSVC与GCC的差异(收集中)
- 依然是cache
- Apache HTTP Server 与 Tomcat 的三种连接方式介绍
- 『转』度百死去飞秋一个BUG引发的血案
- 轻松破解防盗链
- 程序人生--一个程序员对学弟学妹建议(转)
- Redhat Linux IP地址配置笔记
- Java Annotation 介绍(转)
- Java软件开发规范