This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]