Re: Macros
- Posted by Bernie Ryan <xotron at BUFFNET.NET> May 05, 2000
- 429 views
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