[英]Warning on direct access to struct member returned by function
是否有 GCC 警告標志,如果 function 返回結構並且直接訪問該結構的成員( function().x ),則打印警告。
謝謝,湯姆
struct my my_function();
int main(){
int a;
struct my b;
int c;
// There shold be a warning:
a = my_function().member1;
// This is OK:
b = my_function();
c = b.member1;
}
不,GCC 中沒有這樣的警告。
您可以通過使用-Wall -Wextra
編譯以打開所有警告選項來測試 GCC 中的警告選項。 如果存在這樣的警告,這將顯示它並顯示其名稱。 Godbolt表明對此沒有任何警告。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.