
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Difference Between Inline and Macro in C++
In this post, we will understand the difference between inline and macro in C++.
Inline
It is a function in C++.
It is parsed by the compiler.
It can be defined inside or outside the class.
It evaluates the argument only once.
The compiler may not convert all functions to ‘inline’ function and expand them all.
The short functions that are defined inside the class are automatically made as inline functions.
An inline function inside a class can access the data members of the class.
Inline function can be terminated using curly brackets.
It is easy to debug.
This is because error checking is done during compilation.
It binds all statements in the body of the function.
Example
inline return_type funct_name ( parameters ) { . . . }
Macro
It is expanded by the preprocessor.
It is defined at the beginning of the program.
It evaluates the argument every time it is used inside the code.
They always need to be/are expanded.
They need to be defined specifically.
They will never become members of class.
They can’t access data members of the class.
Definition of macro ends with the new line.
It is difficult to debug macros since error checking doesn’t happen during compile time.
It encounters binding problem if it contains more than one statement since it doesn’t have a termination symbol.
Example
#define macro_name char_sequence
- Related Articles
- What is the difference between Macro-Processors and Pre-Processors?
- What is the difference between anonymous and inline functions in JavaScript?
- How to remove the space between inline/inline-block elements in HTML?
- Inline-level Elements and Inline Boxes in CSS
- What are the differences between inline JavaScript and External file?
- Panic! Macro in Rust Programming
- Macro Environmental Factors in Fashion Industries
- HTML Block and Inline Elements
- How to remove the space between inline-block elements?
- How to use F() macro in Arduino?
- What is a Macro Virus?
- Difference Between & and &&
- Inline Functions in C++
- Inline Subheadings in Bootstrap
- Sodium, Potassium and Iodine are macro minerals or trace minerals.
