From -3657521502008689569
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,765aa557d15ef5ba
X-Google-Attributes: gidf78e5,public
X-Google-Thread: fc772,a175c482da34ebf8
X-Google-Attributes: gidfc772,public
X-Google-ArrivalTime: 2003-05-11 02:57:54 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uwm.edu!rpi!not-for-mail
From: LLeweLLyn <llewelly.at@xmission.dot.com>
Newsgroups: comp.lang.c++.moderated,comp.std.c++
Subject: Re: Preprocessor evolution
Date: 11 May 2003 06:00:00 -0400
Organization: The Illusory Sorting Algorithm
Lines: 56
Sender: cppmods@netlab.cs.rpi.edu
Approved: francis.moderator@robinton.demon.co.uk
Message-ID: <m1addw6pf9.fsf@localhost.localdomain>
References: <652361f.0304032218.6b7a67e4@posting.google.com>
 <d6651fb6.0304070135.2222325e@posting.google.com>
 <3e920e1f.883270640@News.CIS.DFN.DE>
 <d6651fb6.0304090204.3dec4b7@posting.google.com>
 <d6651fb6.0304110620.6f41227f@posting.google.com>
 <RHqB1kAqQTo+EwzI@robinton.demon.co.uk>
 <m1u1cr4a3r.fsf@localhost.localdomain>
 <7f2735a5.0304241045.14708662@posting.google.com>
 <m1k7d915u6.fsf@localhost.localdomain>
 <7f2735a5.0305081132.10b62f29@posting.google.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
X-Auth: PGPMoose V1.1 PGP comp.std.c++
	iQBFAgUAPr1HJeEDnX0m9pzZAQHPuwGAoSGiLHUFQyCxjbRUqRI9IlJqNWVxjH2e
	3hJDCscvUL9WdPfzcVeSlMov4FTcXzik
	=aDo8
X-Approved-For-Group: Fergus Henderson <fjh@cs.mu.oz.au> comp.std.c++
X-Original-Date: 10 May 03 18:38:14 GMT
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated
	iQBVAwUAPr4fHUHMCo9UcraBAQEBgAH8D6qsuP8QY7yhcEvNbEpVhj8qKPsK4cDA
	nNislhM2InVMEOWdFLsxSh4T4WHhPxwNDaUJCw8LUqv9yXdBERVDDA==
	=NFKx
Xref: archiver1.google.com comp.lang.c++.moderated:65833 comp.std.c++:19343

allan_w@my-dejanews.com (Allan W) writes:

>  > > LLeweLLyn <llewelly.at@xmission.dot.com> wrote
>  > > > Also, since the preprocessor is not going away, I would like to see an
>  > > >     alternative to function like macros that do not require such
>  > > >     things as the do{}while(0) idiom and parentheses around all
>  > > >     arguments. I can't think of a good way to express this (yet) but
>  > > >     that's what I want.
> 
>  > allan_w@my-dejanews.com (Allan W) writes:
>  > > How about making them functions -- but still expand inline?
>  > > We could call these "inline functions."
>  > >
>  > > :-)
> 
> LLeweLLyn <llewelly.at@xmission.dot.com> wrote
>  > Rewrite this macro as an inline function:
>  >
>  > #define TRACE() do{\
>  >     if(debug_this_module) {\
>  >         logfile << __FILE__ << ":" << __LINE__ << ":" << endl; logfile\
>  >         << dump_stack_trace();\
>  >     }\
>  > }while(0)
>  >
>  > :-)
> 
> // USAGE: TRACE(__LINE__);
> void TRACE(int line=0) {
>      if (debug_this_module)
>          logfile << __FILE__ << ": " << line << ":\n" << dump_stack_trace();
> }

I think you miss half the point. Requiring the user to specify
    __LINE__ and __FILE__ is only an opportunity for error. (In
    pracitice, I always use __func__ or __PRETTY_FUNCTION__ where
    available, as well as __FILE__ and __LINE__.) Further, __FILE__
    expands to a string literal containing the file name. If TRACE is
    used in a file different from where it is defined, your definition
    will print the wrong file name.   

> If dump_stack_trace can be modified to accept a parameter int ignore=0,
> then TRACE() could be changed to pass in 1, meaning "ignore the very
> first stack frame".
> 
> :-)

As a student, I consistently used functions for this sort of thing -
    but after I started working professionly, I switched to macros -
    so much easier, despite their problems.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



