2010-11-22 38 views
35

我不小心把我的函数定义的左括号return语句为什么GCC会说“不再支持命名的返回值”?

int id(int k) return k; { } 

之后,但GCC与一个奇怪的错误消息

error: named return values are no longer supported

回答任何人都可以请解释一下这是什么奇怪的特征可能是什么?我从来没有听说过。

+0

也许有一些早期的NRVO实现,你必须命名变量才能让它复制副本? – 2010-11-22 14:38:54

+0

Go命名了结果参数,http://golang.org/doc/effective_go.html – u0b34a0f6ae 2011-11-11 11:35:39

回答

37

请参阅here - 通过显式定义函数头中指定的返回值来实现早期的NRVO实现。

本次支持NRVO没有这个扩展名被添加here - GCC 3.1发布系列。

简要剪切和粘贴上下文:

G++ now supports the "named return value optimization": for code like

A f() { 
    A a; 
    ... 
    return a; 
} 

G++ will allocate a in the return value slot, so that the return becomes a no-op. For this to work, all return statements in the function must return the same variable.

相关问题