我試圖推行「標籤的價值」的價值觀(https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html)使用鐺3.7在Visual Studio 2015年標籤是鐺
作爲一個玩具示例性交流計劃,我有以下代碼會導致編譯編譯器文件'c:\ agent \ build \ cache \ git \ vctools \ vctools \ compiler \ utc \ src \ p2 \ main編譯器文件'c:\ agent \ build \ cache \ git \ .c',第246行) 1>要解決此問題,請嘗試簡化或更改上述位置附近的程序。「)。
const void *array_jump[] = {&&S1,&&S2,&&S3,&&S3,&&S4};
S1:
goto *array_jump[3];
S2:
return 2;
S3:
return 3;
S4:
return 4;
如果我移動陣列聲明畢竟它的工作標籤,直到我包括任何語句的array_jump變量。
S1:
//comment out and add "return 1;" and it will compile fine
goto *array_jump[3];
S2:
return 2;
S3:
return 3;
S4:
return 4;
const void *array_jump[] = {&&S1,&&S2,&&S3,&&S3,&&S4};
任何人都可以提供一個像上面那個應該工作的例子嗎?這是鏗鏘聲或Visual Studio的「codegen」方面的問題嗎?
我覺得這個bug是相關的,但我不知道: https://connect.microsoft.com/VisualStudio/feedback/details/2103400/crash-in-clang-c2-with-address-of-label-extension
這是可怕的編碼風格。你爲什麼不使用'switch'或函數表。如果你真的想要這樣的代碼,你應該'goto' 70ies/80ies BASIC。 – Olaf