Understanding Macro Pre-processor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux