+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Newbie level 4
    Points: 1,323, Level: 8

    Join Date
    Oct 2005
    Posts
    7
    Helped
    0 / 0
    Points
    1,323
    Level
    8

    diffrence between macros and inline function

    hi

    what is the difference between macro and the inline functions.

  2. #2
    Junior Member level 3
    Points: 1,496, Level: 8

    Join Date
    Nov 2005
    Posts
    28
    Helped
    1 / 1
    Points
    1,496
    Level
    8

    Re: c

    macro's doesnt check for syntactical errors
    for inline there is syntactical check .....



    •   Alt26th December 2005, 09:00

      advertising

        
       

  3. #3
    Full Member level 5
    Points: 3,353, Level: 13
    dipal_z's Avatar
    Join Date
    Apr 2005
    Location
    India
    Posts
    278
    Helped
    38 / 38
    Points
    3,353
    Level
    13

    c

    Usage of macros is always replaced with actual code (i.e. they are always in lined) While its up to the compiler to decide whether to replace the inline function call to function code or keep it as function call. There are some guidelines to be followed to make sure that your inline function is replaced with its code but even after following those guidelines its not guaranteed.



  4. #4
    Full Member level 2
    Points: 2,806, Level: 12

    Join Date
    Nov 2005
    Posts
    137
    Helped
    31 / 31
    Points
    2,806
    Level
    12

    c

    Although inline functions are similar to macros (because the function code is expanded at the point of the call at compile time), inline functions are parsed by the compiler, whereas macros are expanded by the preprocessor. As a result, there are several important differences:

    * Inline functions follow all the protocols of type safety enforced on normal functions.
    * Inline functions are specified using the same syntax as any other function except that they include the inline keyword in the function declaration.
    * Expressions passed as arguments to inline functions are evaluated once. In some cases, expressions passed as arguments to macros can be evaluated more than once.



    •   Alt12th January 2006, 07:49

      advertising

        
       

  5. #5
    Full Member level 4
    Points: 3,412, Level: 13
    ivar4ever's Avatar
    Join Date
    Jun 2006
    Location
    India
    Posts
    189
    Helped
    79 / 79
    Points
    3,412
    Level
    13

    Re: c

    macros dont make the part of Code Segment Memory, but inline functions are a part of code segment.
    Macro Expansion is a preprosessing time activity and inline function resolution (whether to accept the request for Inline or not) is a compile time activity.



  6. #6
    Advanced Member level 3
    Points: 7,502, Level: 20
    salma ali bakr's Avatar
    Join Date
    Jan 2006
    Posts
    973
    Helped
    103 / 103
    Points
    7,502
    Level
    20

    Re: c

    macros are used if timing is more important
    while inline functions are used when memory usage is more important



  7. #7
    Banned
    Points: 2,196, Level: 10

    Join Date
    Jun 2006
    Posts
    160
    Helped
    34 / 34
    Points
    2,196
    Level
    10

    c

    A macro in computer science is an abstraction, whereby a certain textual pattern is replaced according to a defined set of rules. The interpreter or compiler automatically replaces the pattern when it is encountered. In compiled languages, macro-expansion always happens at compile-time. The tool which performs the expansion is sometimes called a macro-expander. The term macro is used in many similar contexts which are derived from the concept of macro-expansion, including keyboard macros and macro languages. In most situations, the use of the word "macro" implies expanding a small command or action into a larger set of instructions.

    The purpose of macros is to either automate frequently-used sequences or enable a more powerful abstraction — but these are often the same thing.


    In computer science, an inline function is a programming language construct used to suggest to a compiler that a particular function be subjected to in-line expansion; that is, it suggests that the compiler insert the complete body of the function in every context where that function is used.



  8. #8
    Newbie level 4
    Points: 1,313, Level: 8

    Join Date
    Nov 2005
    Posts
    7
    Helped
    0 / 0
    Points
    1,313
    Level
    8

    Re: c

    1. macros are processed by the preprocessor while inline functions are processed by the compiler.

    2. macros are marginally faster

    3. Arguments for inline functions are typed, therefore compiler can apply some type checking to that function calls.
    Macro isn't type checked and does not evaluate arguments, but simply takes the string passed to the macro and replace each occurence of macro argument in the text of macro with actual string for that parameter. It may give you sometimes very surpising results.



  9. #9
    Newbie level 1
    Points: 13, Level: 1

    Join Date
    Sep 2013
    Posts
    0
    Helped
    0 / 0
    Points
    13
    Level
    1

    Re: what is the difference between macro and the inline function

    Per this article:

    inline vs macro

    "Inline functions are parsed by the compiler, whereas macros are expanded by the C++ preprocessor."

    It's also said that debugging macros is difficult.



+ Post New Thread
Please login