我想知道每個存儲類之間究竟有什麼區別。在這裏我使用了寄存器存儲類。所以我很疑惑,如果我們將register變量聲明爲全局變量,它的範圍是什麼? 在我的代碼中,它給出了沒有爲'x'指定的寄存器名稱。如果有人知道它究竟是什麼意思,並且與其他存儲類相比,寄存器varibale的範圍是多少,請指導我? 謝謝。寄存器存儲類的範圍是什麼?
below is the output of terminal using gcc compiler in Ubuntu.
[email protected]:~/storageclass$ gcc register.c
register.c:9:15: error: register name not specified for ‘x’
register int x=10;
^
[email protected]:~/storageclass$ gcc register.c
register.c:9:15: error: register name not specified for ‘x’
register int x=10;
^
//int x = 10 ;
int z;
int main()
{
extern int y ;
// register int x ;
printf ("The value of x is %d \n", x) ;
printf ("The value of y is %d",y) ;
z=add();
printf("\nvalue of sum is : %d", z);
return 0;
}
int y = 200 ;
int add()
{
int sum;
sum=x+y;
//printf("value of sum is : %d", sum);
}
此錯誤是否屬於發佈代碼? – 2014-09-25 12:54:30
忘記簡單地'註冊'關鍵字。有沒有不忽略該關鍵字的編譯器?正如我記得我看到的最後一個有效代碼是在八十年代初。 ;) – Klaus 2014-09-25 12:55:39
「寄存器變量的範圍對聲明它的塊是本地的。」 – 2014-09-25 12:56:26