Re: Macros

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Fri, 5 May 2000 16:59:33 -0400, Chris Bensler <bensler at MAILOPS.COM>
wrote:
>Would you elaborate? Give me a simple example maybe pls? An occasion when
>this would be useful?

Chris:


 This is a very simple example

 In the "C" language I could use a MACRO like this:

 #define MyMacroName(ExprA)         ( (ExprA) * 20 )

 Now in my progam I use this:

 answer = MyMacroName(7 + 10)
 answer = MyMacroName( 487 + 10/523 )

 Then the compiler will put this in my program.

 answer = 7 + 10 * 20
 answer = 487 + 10/523 * 20

 In other words the compiler looks at the preprocessor #define

 statement and knows that we want to substitute something for MyMacroName

 The compiler then takes whatever the programmer inserts in place of

 ExprA and substitues it into the right side of the macro where ever

 it sees the ExprA ( Note the parenthes are part of the MACRO and are NOT

 inserted in the substitution )

 Macros can be very complicated but they can save allot of typing

 and make it easier because you only have to change a MACRO in one place

 and the rest of your program will be change by recompiling.

 Bernie

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu