2010-11-22 133 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.

相關問題