C语言抽象声明

MSDN上的原文:http://msdn.microsoft.com/en-us/library/b198y5xs(v=vs.80).aspx
译文:
抽象声明指的是一种没有标识符(identifier)的声明形式,它包含一个或多个指针(pointer)修饰符,数组(array)修饰符,函数(function)修饰符。在声明式中指针修饰符通常是位于标识符前面;数组修饰符(”[ ]”)和函数修饰符(”()”)则位于标识符后面。了解这些内容之后,你就能够判断标识符将会出现在抽象声明的哪个位置,并且能够据此解释这个声明式的含义。要获取详细信息和一些关于复杂声明的例子可以看“Interperting More Complex Declarators”的内容。此外, typedef通常能够应用于简单的声明,详情看“Typedef Declarations”。

 

以下是一些阐述抽象声明的例子:

int *         // The type name for a pointer to type int:

 

int *[3]      // An array of three pointers to int

 

int (*) [5]   // A pointer to an array of five int

 

int *()       // A function with no parameter specification

              // returning a pointer to int

 

// A pointer to a function taking no arguments and

// returning an int

 

int (*) ( void )

 

//An array of an unspecified number of constant pointers to

//functions each with one parameter that has type unsigned int

//and an unspecified number of other parameters returning an int

 

int (*const []) ( unsigned int, ... )

 

注意:

包含一系列空括号(),的抽象声明是不被允许的,因为这样会产生歧义。判断隐含的标识符是属于括号内部(当它是一个没有限制符的类型修饰时,属于这种情况)还是位于括号的前面(当它是一个函数类型时,属于这种情况)是很重要的。

posted @ 2012-03-21 23:14  crazylhf  阅读(394)  评论(0)    收藏  举报