This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Understanding Macro Pre-processor
- From: "Bruno Moreira Guedes" <thbmatrix at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 20 Sep 2007 16:43:45 -0300
- Subject: Understanding Macro Pre-processor
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;
cin>>a;
cin>>b
c=mul(a,b)
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