MY mENU


Saturday 23 June 2012

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, 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, butwithout it no real work gets done.

2 comments:

Jacob Swanner said...

Perhaps this is a bit off topic but in any case I have been surfing about your blog and it looks really neat. impassioned about your writing. I am creating a new blog and hard-pressed to make it appear great and supply excellent articles. I have discovered a lot on your site and I look forward to additional updates and will be back. http://scarprin.info/

Unknown said...

Thanks for the post and information! I think education is important for us so we must prepare the best education for our generation by sharing such great information with each other!
yard furniture

Post a Comment