有趣的goto語句

#include<stdio.h>
int falge = 1;
void my_init( void )
{
int count = 0;
if ( falge == 1 ) {
goto that;
} else {
goto those;
}


//those: printf("This is goto those!\n");


that: printf("This is goto that!\n");  
 count++;


 if ( count == 3 )

 goto exit;

//break      這個break 是不合法的!  但是如果沒有此處的if 判斷 這是一個死循環!  不能使用break的死循環



those: printf("This is goto those!\n"); goto that;


exit: printf("exit goto!\n");
}


void main( void )
{
my_init();

}



感覺goto語句蠻好玩


而且長得很奇怪:

0,執行完

that: printf("This is goto that!\n");  

       會接着執行

those: printf("This is goto those!\n");

1,注意those也是一個標號,而且執行呢!

猜測:goto的標誌 是不是編譯器記錄了標記處cs:ip,那麼這個過程應該發生在編譯的時候,是不是很像 彙編裏面的jmp?

發佈了33 篇原創文章 · 獲贊 11 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章