causes the preprocessor to exchange subsequent instances of the identifier with the given sequence of tokens; leading and trailing white space round the token sequence is discarded.

A second #define for an equivalent identifier is erroneous unless the second token sequence is identical to the primary ,where all white space separations are taken to be equivalent.A line of the form

#define identifier (identifier-list) token-sequence

where there’s no space between the primary identifier and therefore the (, may be a macro definition with parameters given by the identifier list.As with the primary form, leading and trailing white space arround the token sequence is discarded, 

and therefore the macro could also be redefined only with a definition during which the amount and spelling of parameters, and therefore the token sequence, is identical.

A control line of the form

#undef identifier

causes the identifier’s preprocessor definition to be forgotten. It is not erroneous to apply #undef to an unknown identifier.

When a macro has been defined within the second form, subsequent textual instances of the macro identifier followed by optional white space,then by (, a sequence of tokens separated by commas, and a ) constitute a call of the macro.

The arguments of the decision are the comma separated token sequences; commas that are quoted or protected by nested parentheses don’t separate arguments.

During collection, arguments are not macro-expanded. The number of arguments in the call must match the number of parameters in the definition.After the arguments are isolated, leading and trailing white space is faraway from them.

Then the token sequence resulting from each argument is substituted for every unquoted occurrence of the corresponding parameter’s Identifier within the replacement token sequence of the macro.

Unless the parameter within the replacement sequence is preceded by #, or preceded or followed by ##,the argument tokens are examined for macro calls, and expanded as necessary, just before insertion.

Two special operators influence the replacement process.First, if an occurrence of a parameter within the replacement token sequence is instantly preceded by #, string quotes (“)

are placed round the corresponding parameter, then both the # and therefore the parameter identifier are replaced by the quoted argument.

A character is inserted before each ” or character that appears surrounding, or inside, a string literal or character constant within the argument.Second, if the definition token sequence for either quite macro contains a ## operator, then just after replacement of the parameters,

each ## is deleted, along side any white space on either side, so as to concatenate the adjacent tokens and form a new token.

The effect is undefined if invalid tokens are produced, or if the result depends on the order of processing of the ## operators. Also, ## might not appear at the start or end of a replacement token sequence.

In both sorts of macro, the replacement token sequence is repeatedly rescanned for more
defined identifiers.

However, once a given identifier has been replaced during a given expansion, it is not replaced if it turns up again during rescanning; instead it’s left unchanged.Even if the ultimate value of a macro expansion begins with with #, it’s not taken to be a
preprocessing directive.

If you like this post, don’t forget to share 🙂

This article is written by our awesome writer
Comments to: Macro Definition and Expansion In C

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Explore Tutorials By Categories

Login

Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
  •  
    Strength indicator
  •  
  •  
    Log In | Lost Password