Actions

EmSys

C - Macro Substitution

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Macro Substitution

  • A control line of the form
#define  identifier  reptext

causes the preprocessor to replace subsequent instances of the identifier with the given sequence of reptext.

  • A control line of the form
#define  identifier(parlist)

Where there is no space between the first identifier and the (, is a macro definition with parameters given by the parlist.

  • e,g:
#define   MAX_TABSIZE   100
int table[MAX_TABSIZE];
#define  ABSDIFF(a, b)  ( (a) > (b) ? (a) – (b) : (b) – (a) )
#define  max(a,b)       ( (a) > (b) ? (a) : (b) )
  • A control line of the form
#undef    identifier

causes the identifier’s preprocessor definition to be forgotten.