![](/img/trans.png)
[英]Possible bug in Visual Studio 2010 linker (minimal testcase included)
[英]A Visual Studio 2010 Bug?
我想我在VS2010(C / C ++)中發現了一個錯誤,但它看起來很明顯,我無法相信。
( 選擇的靜脈不是破碎的 )。
如果這是一個錯誤,或者如果我遺漏了某些內容,請告訴我:
int main(void)
{
int x; // Declare a variable x;
for(int i=0, x = 10; i<5; ++i) // Initialize X to 10. No way around this.
{
printf("i is %d\n", i);
}
if (x == 10) // warning C4700: uninitialized local variable 'x' used
{
printf("x is ten\n");
}
}
int i=0, x = 10;
您剛剛聲明了第二個x
變量作為for
循環。
外部x
變量不受影響。
要測試它,您應該嘗試在不同的編譯器中編譯代碼。 使用gcc(不帶-Wall -Wextra -Wpedantic
標志):
$ gcc a.c
a.c: In function ‘main’:
a.c:7: error: redeclaration of ‘x’ with no linkage
a.c:5: error: previous declaration of ‘x’ was here
a.c:7: error: ‘for’ loop initial declaration used outside C99 mode
a.c:9: warning: too few arguments for format
a.c:9: warning: too few arguments for format
如上所述,問題是您在for循環中聲明了一個不同的變量,范圍更小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.