The difference between a macro and a function.

1. The macro consume the pre-process time and function consume compile time. The macro will not immediate invoke function call.

2. The macro does not have return value, it will only substitute statement.

3. The parameter in macro does not have a specific type. The parameter in function does.

4. The  argument , when represented as a expression, will be calculated first then pass to the function. The argument will not, it will substitute directly.

5. The macro may have some unexpected side-effect.

Nowadays, people prefer inline function(compile) to macro(pre-process).

Advertisements
This entry was posted in C++. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s