Discussion: How to debug macro?
Afficher un message
Vieux 30/06/2008, 07h51   #5
Greg Herlihy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to debug macro?

On Jun 28, 9:23pm, Peng Yu <PengYu...@gmail.com> wrote:

> It is benifitical to use macro in certain cases.


Perhaps, but the example below certainly isn't one of them.

>
> #define MACRO_DEF \
> class A { \
> public: \
> A(int a) : _a(a) { } \
> int the_a() const { return _a; } \
> private: \
> int _a; \
> };
>
> MACRO_DEF
>
> #define MACRO \
> A a(1);\
> std::cout << a.the_a() << std::endl;


> However, I found that it is not easy to debug a macro. For example,
> for the following program, I can not trace into the last macro in gdb.


If you (who wrote the macro) have trouble debugging it, imagine the
difficulties that the maintenance programmer will face - simply to
understand what the macro is supposed to do. After all, what would you
think if you had to debug a C++ program whose main() function looked
like the main() in your program:

> int main() {
> MACRO
>
> }


Having to deal with code like this, in my experience, would be enough
to convince most programmers that they really should be working -
somewhere else.

Greg

  Réponse avec citation
 
Page generated in 0,45251 seconds with 9 queries