Pages

Wednesday, February 5, 2014

RESOLVING C DECLARATIONS

ALGORITHM FOR RESOLVING C DECLARATION

OPERATORS: * & () [] ,
PRECEDENCE (DECREASING ORDER): () [] * & ,
ASSOCIATIVITY (POSTFIX): () [] 
ASSOCIATIVITY (PREFIX): * &

Meaning: 
   [] : array of
   () : function taking ... and returning 
   *  : pointer to 
   &  : reference to {address of}
   ,  : and
1. FIND THE IDENTIFIER
2. RESOLVE THE OPERATORS ON THE RIGHT. EG: () , []
   IF () THEN RESOLVE THE FUNCTION ARGUMENTS
3. RESOLVE OPERATORS (EG: *) and TYPES ON THE LEFT
4. REPEAT 2 & 3 TILL NOTHING LEFT UNRESOLVED
Few Examples Of Resolving Complex Declaration. References: Clockwise Spiral Rule

No comments: