Advantages of a macro over a function

Macro gets to see the Compilation environment, so it can expand
____TIME__ __FILE__ #defines. It is expanded by the preprocessor.

For example

It can’t do this without macros:
#define PRINT(EXPR) printf( #EXPR “=%dn”, EXPR) 
PRINT( 5+6*7 ) // expands into printf(”5+6*7=%d”, 5+6*7 ); 

You can define your mini language with macros:

#define strequal(A,B) (!strcmp(A,B)) 

Macros are a necessary evils of life. The purists don’t like them, but

without it no real work gets done.

De admin

Lasă un răspuns

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *

The reCAPTCHA verification period has expired. Please reload the page.