2014-09-29 77 views
-2

Can a Macro with a goto statement and a label be defined?可以定義具有goto語句和標籤的宏嗎?

+2

如果你足夠瘋狂的做,你可以定義你的整個程序作爲一個巨大的宏觀兩者。 – gnasher729 2014-09-29 13:16:19

+0

這個問題怎麼不清楚? – NPE 2014-09-29 13:19:29

+0

真正的問題是你爲什麼要這麼做 – 2014-09-29 13:19:29

回答

1

宏是一個文本替換由預處理器照顧,所以,你可以。您可以爲goto語句和/或標籤定義一個maro。

Ps。反正是一個可怕的做法..使用大量的宏和使用goto方法

#include <iostream> 

#define GOTOSTMT goto helloworld; 
#define LABELSTMT helloworld: 

int main() { 

    int i = 0; 

    LABELSTMT 

    std::cout << "Don't ever program like this" << std::endl; 
    i++; 
    if(i < 3) 
     GOTOSTMT 

} 
+0

隨機downvoter請解釋你的理由 – 2014-09-29 15:02:25