+ Reply to Thread
Results 1 to 2 of 2

Thread: What is Multi Line macro?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    49

    What is Multi Line macro?

    Hi All,

    What is Multi-Line macro? How to define it?

    Thanks

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    Hello,

    Following is an example describing MultiLine Macro:

    Code:
    #define DEGREE_CELCIUS_TO_FAHRENHEIT 1
    #define FAHRENHEIT_TO_DEGREE_CELCIUS 2
    
    //Please note that "\" does not required at the end of last line.
    
    #define TEMPERATURE_CONVERSION(temp, conversionType) \
    		(DEGREE_CELCIUS_TO_FAHRENHEIT == conversionType) \
    			? \
    				( ( ( (temp) * (9) ) / (5) ) + (32) ) \
    			: \
    				( ( ( (temp) - (32) ) * (5) ) / (9) )
    
    void UseMultiLineMacro()
    {
    	int nTemperature	= TEMPERATURE_CONVERSION(10, DEGREE_CELCIUS_TO_FAHRENHEIT) ;
    	nTemperature	= TEMPERATURE_CONVERSION(nTemperature, FAHRENHEIT_TO_DEGREE_CELCIUS) ;
    }
    Tips:
    a. It is advisable to use MACRO as less as possible because it is not type safe.
    b. In some cases, expressions passed as arguments to macros can be evaluated more than once.
    c. In C++, user should consider using inline function which is more convenient than a MACRO.

    Thanks

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts