C: Comments on Declaration/Definition Syntax

From: C: An Advanced Introduction” (Narai Gehani) – 1984 – ISBN 0-88175-053-0

The syntax for declarations and definitions in C is similar to the syntax used for accessing values of these objects; that is, it is similar to the syntax used to represent object values in expressions. This is an important difference between C and languages like ALGOL 68, Pascal and Ada, where the syntax used for declaring object types reflects the structure of the type. Declarations and definitions in C are sometimes hard to read and understand, particularly if they involve compound-type expressions that contain the pointer dereferencing operator *. The primary reason for this difficulty is that the dereferrencing operator is a prefix operator, while all the other operators used in declarations and definitions are postfix operators. The reader unaccustomed to programming in C may at first find it hard to understand definitions and declarations such as


int *(*(*x)[6]()
char (*(*(y())[])(); /* take form ANDE80 */

where

1. x is defined to be a pointer to an array of 6 elements each of which is a pointer to a function returning a pointer to an integer object.
2. y is declared as a function that returns a pointer to an array of pointers to functions that return character values.

The reader will find it easier to undestand C declarations and definitions if he/she keeps in perspective that an object declaration or definition looks very much like the way the object will be referenced in an expression.

  • Share/Bookmark

Post a Comment

Your email is never shared. Required fields are marked *

*
*