Your Ad Here
0

What are the advantanges of macro over a function ?

Posted by The Blogger on 9:08 AM in
Answer:

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

For example, you can’t do this without macros
#define PRINT(EXPR) printf( #EXPR “=%d\n”, 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.


tags: c interview questions and answers, c interview question What are the advantanges of macro over a function, What are the advantanges of macro over a function, advantages of macro, macro, function

0 Comments

Post a Comment

Your Ad Here

Copyright © 2009 Interview Questions and Answers