Macro substitution

Nasza ocena:

3
Wyświetleń: 567
Komentarze: 0
Notatek.pl

Pobierz ten dokument za darmo

Podgląd dokumentu
Macro substitution - strona 1 Macro substitution - strona 2 Macro substitution - strona 3

Fragment notatki:

Macro substitu tion  A definition has the form #define name replacement_text  Subsequent occurrences of the token name will be replaced by the replacement_text  The name in a #define has the same form as a variable name  The replacement text is arbitrary  The replacement text is the rest of the line  Example: #define MINT -60 #define MAXT 300 ... for (i = MINT; i (B)?(A):(B)) #define max(A, B) ((A)(B)?(A):(B))  A use of max expands into in-line code  Example: x = max(p+q, r+s); will be replaced by the line x = ((p+q) (r+s) ? (p+q) : (r+s));  This macro will serve for any data type

(…)

… definition may be continued onto
several lines by placing a \ at the end of each
line to be continued
 Example:
#define TENLINES for(i=0; \
i<10;i++) printf("Hello\n");
...
int i;
TENLINES
 A definition may use previous definitions
 Example:
#define PR printf("Hello\n");
#define TENL for(i=0;i<10;i++) PR
...
int i;
TENL
 Substitutions are made only for tokens, and
do not take place within quoted strings…
... zobacz całą notatkę



Komentarze użytkowników (0)

Zaloguj się, aby dodać komentarz