Home »

What is difference between template and macro??

Question ListCategory: cWhat is difference between template and macro??
shah_kajal184 author asked 8 years ago
1 Answers
denielshakespeare5 author answered 8 years ago

There is no way for the compiler to verify that the macro parameters are of compatible types.
The macro is expanded without any special type checking.

If macro parameter has a postincremented variable ( like c++ ), the increment is performed

two times.

Because macros are expanded by the preprocessor, compiler error messages will refer to

the expanded macro, rather than the macro definition itself. Also, the macro will show up in

expanded form during debugging.

for example:

Macro:

#define min(i, j) (i < j ? i : j)

template:

template<class T>

T min (T i, T j)

{

return i < j ? i : j;

}

Please login or Register to Submit Answer