A very slight correction 
if (p) throw 0;
should be
if (!p) throw 0;
otherwise, the macro will throw every time 
Cheers,
Stoyan
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Stoyan Damov
Sent: Wednesday, June 23, 2004 09:04
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to disable warning for a macro?
And here comes the dreaded solution:)
#define TTRACE_IF(Area, Level, Action) \
if (TraceEnabled(Area, Level)) \
{ \
try \
{ \
Action; \
int a = Area; int* p = &a; if (p) throw 0; \
} \
catch (…) \
{ \
ReportProblem(); \
} \
}
Voila, the warning goes away 
Cheers,
Stoyan
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Stoyan Damov
Sent: Wednesday, June 23, 2004 08:41
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to disable warning for a macro?
Hi,
I have compiled the code with warning level 4 and it compiles without
warnings. However if your Action is a function, given a throw() exception
specification you get the unreachable code detected warning.
#define TTRACE_IF(Area, Level, Action) \
if (TraceEnabled(Area, Level)) { \
try { \
Action; \
} \
catch (…) { \
ReportProblem(); \
} \
}
bool TraceEnabled(int area, int level)
{
return (area == level);
}
void ReportProblem() {}
void ActionThatCannotThrow() throw() {}
void ActionThatCanThrow() {}
int _tmain(int argc, _TCHAR* argv)
{
argc; argv;
TTRACE_IF(1, 2, ActionThatCanThrow()) // OK
TTRACE_IF(1, 2, ActionThatCannotThrow())// warning C4702
return 0;
}
HTH,
Stoyan
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Wednesday, June 23, 2004 04:51
To: Windows System Software Devs Interest List
Subject: [ntdev] How to disable warning for a macro?
I have a trace macro which looks like this in C++ version (simplified):
#define TTRACE_IF(Area, Level, Action) \
if (TraceEnabled(Area, Level) { \
try { \
Action; \
} \
catch (…) { \
ReportProblem(); \
} \
}
Action is a block of code called only in debug version when trace area is
enabled for given level. It works as designed. The problem is when Action
can’t throw an C++ exception, compiler (.NET 2003) reports warning C4702:
unreachable code on catch (…) statement. I don’t want to turn off this
warning globally; just for this macro expansion. For lint it is easy but I
haven’t found a way how to do it for VS. #pragma warning(disable/default:
4702) around the macro doesn’t work. Any idea?
Best regards,
Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@code.bg
To unsubscribe send a blank email to xxxxx@lists.osr.com
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@code.bg
To unsubscribe send a blank email to xxxxx@lists.osr.com
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@code.bg
To unsubscribe send a blank email to xxxxx@lists.osr.com