2014-11-25 48 views
-3
static void fubar(int a) 
{ 
    void (*b) (int) = fubar; // <--- 
    static int c; 
} 

http://cdecl.org/表示語法錯誤。'(* b)(int)= fubar''意思?

我的猜測是b是一個返回int的函數的指針。它是否正確?

+0

不,這只是一個語法錯誤。沒有其他意義。 – 2014-11-25 05:27:05

+3

不要不誠實。原始代碼片段顯示在這裏(http://ieng9.ucsd.edu/~cs30x/Quiz4.sp12.pdf)(這裏不是語法錯誤)。 – 2014-11-25 05:30:22

+0

@remyabel靜態語法錯誤:http://tinyurl.com/lx24s4b – penu 2014-11-25 05:41:26

回答

1

My guess is that b is a pointer to a function returning int. Is this correct?

你是接近正確答案。它實際上是指向返回類型void和類型爲int的函數的指針。

正如你可以從代碼中看到的片斷

static void fubar(int a) 
{ 
    void (*b) (int) = fubar; // <--- 
    static int c; 
} 

在分配的右側有一個已經聲明如下 void fubar(int a)標識符fubar。所以在函數內部,只需將它賦值給相同類型的指針即可。

3

必須有一些返回類型,

void (*b) (int) = fubar; 

int (*b) (int) = fubar; 

然後,它b將是,指針的函數會返回void/int並採取int作爲參數。

2

必須有一個返回類型此爲

INT(* B)(INT)= FUBAR;

所以這explaines的b是指針,該採取INT作爲參數的函數,它會返回INT值