Sunday, June 7, 2009

About Macrossss...................

A macro definition is contained on one line. If we need to write it on multiple
lines because of its length, we can do so by using the backslash as
a line continuation character
Example:
#define ran(low,high) \
((int)random() % (high-low+1)) \
+ low

========================================================

To change the definition of a macro, it is necessary to delete it and define it
again.
Example:

#define MLKEYVAL 889
#undef MLKEYVAL
#define MLKEYVAL 890
=========================================================

For a macro to be defined as having parameters, there must be no spaces
between the name of the macro and the parentheses.
Example:
#define ADD(a,b) printf("%d\n",a+b)
#define incrint (a) a++

showint(30,10);
incrint(bbls);
following is the result of preprocessing the previous lines:

printf("%d\n",30+10);
(a) a++(bbls)

==========================================================

Macro names are not substituted inside strings, as in the following
Eexample:

#define Gaggu 8192
printf("THE Gaggu KNOWS HOW TO DO.\n");

The output looks like the following:

THE Gaggu KNOWS HOW TO DO.

==========================================================

An argument passed to a macro can be “stringized” by preceding its name with
a hash (#) character. In the following example, the macro named GAGGU contains
a stringized version of its argument, which is combined with other strings (by
being placed adjacent to them):
Example:
#define GAGGU(ZINGALALA) \
printf("The term " #ZINGALALA " is a string\n")

MONCK(KARLOSE);
The output looks like the following:

The term KARLOSE is a string

===============================================================

No comments:

Post a Comment

Search Ranjeet's Blog