Re: Help needed for Trace mechanism for function calls
Tojo ...Thats Me wrote:
I have a requiremnt to put a trace in all my functions when
execution enter in the function and also when execution exist
from it.
I saw some samples to do the same
for eg. Hereis the current method I am using.
Just one small comment, and a meta-comment...
[...]
#define FUNC_TRACE(funcName) FuncHeader obj_##funcName
(#funcName)
Since this line should only be used within a function, and only
once in any given function, you don't really need ## to make it
unique. More important is to use a name so strange no
reasonable programmer is likely to use it. Something along the
lines of "dummy_for_trace_in_functions", for example. (Of
course, whatever you use, the coding guidelines should specify
that a user cannot use it. If, for example, the coding
guidelines insist on camelCase, just about any name with a _ in
it is OK.)
If you really do want distinct names, I would concatenate avec
__LINE__. Something like:
#define paste2( a, b ) a ## b
#define paste( a, b ) paste2( a, b )
#define FUNC_TRACE( funcName ) \
FuncHeader paste( dummy, __LINE__ )( \
#funcName, __FILE__, __LINE__ )
More generally, I would design the tracing mechanism so that it
can be turned on and off dynamically, with a configuration file
or a command line option. And I'd try to make it as cheap as
possible when turned off, so that I could leave it in production
code. (But I'd also try to make it possible to remove entirely,
as you do here. Mainly for political reasons -- I've never
actually had to remove it in delivered code, but the fact that
it could be removed if necessary has been a necessary argument
to get it accepted in the first place.)
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]