6

Possible Duplicate:
Difference between macro and preprocessor

I have a question about macro and preprocessor directives in C++, what is the difference between them? seems like they are more or less the same? I tried to look up on the internet, but still can not understand it, can anyone help?

Community
  • 1
  • 1
  • A macro is a textual symbol replacement definition. `#define` is the preprocessor directive use to define a macro. – jpm Jan 06 '13 at 18:38

2 Answers2

12

A preprocessor directive is any of the language features that starts with a #, e.g. #if, #pragma, #include. They're completely processed by the preprocessor as a separate stage, before the proper compiler kicks in.

A macro is anything defined by a #define; it's just one particular kind of preprocessor directive.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
9

A macro is a subset of preprocessor directives:

#define X

This is a macro and a preprocessor directive.

#pragma once

This is just a preprocessor directive.

Macros begin with #define and define elements that will be expanded at preprocessing time.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • 3
    To be more precise: the `#define` preprocessor directive allows you to create a macro, so in something like `#define X 1234`, `#define` is a preprocessor directive, `X` is a macro, and `1234` is a macro replacement list. – Jerry Coffin Jan 06 '13 at 18:45