Understanding Macro Pre-processor

Bruno Moreira Guedes thbmatrix@gmail.com
Fri Sep 21 01:40:00 GMT 2007

Hi All.

I'm using GCC until I use Linux, and I've always used the compiler and
the C language just basically.
I've been made too basic usage of pre-processor macros(some constants,
conditionals, and other)...

For my surprise, it works different than I've always imagined...
To me, it simply "subst" the text at compile-time.
Since I'm training to the ACM, I've been noted hints about using
macros to make the processing fast. So I think it's happen because the
macros are replaced at compile time... And just it.

Bu I've been made some tests... By example... A macro:

#define mul(X,Y) (X*Y)

It makes the processing faster... But I've passed vars which I've
obtained at the runtime! So I think:
int a,b,c;

The mul(a,b) is replaced by a*b;

But... Why executing that a milion of times is faster than using the
simple a*b itself???
It really happens? Why?

Thanks in the advance!

Bruno M. Guedes

More information about the Gcc-help mailing list