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]

If this is for debug only, try making a dummy type and throw it after
Action, like so:

struct _Dummy;

if (TraceEnabled(Area, Level)) {
try {
Action;
throw _Dummy;
}
catch (const _Dummy &) {
// do nothing
}
catch (…) {
ReportProblem();
}
}

It’s possible the compiler’s still smart enough to realize the
catch(…) will never get executed, but it’s worth a try. Downside is
throwing the _Dummy exception all the time might impact performance.

Chuck

----- Original Message -----
From: “Michal Vodicka”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, June 23, 2004 8:51 AM
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) <br>> if (TraceEnabled(Area, Level) { <br>> try { <br>> Action; <br>> } <br>> catch (…) { <br>> ReportProblem(); <br>> } <br>> }
>
> 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@cbatson.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

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

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 :slight_smile:

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

A very slight correction :slight_smile:

if (p) throw 0;

should be

if (!p) throw 0;

otherwise, the macro will throw every time :slight_smile:

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 :slight_smile:

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

The warning goes away, however “if (p)” will always be true, thus
throwing 0 and causing ReportProblem() to be called, which is presumably
undesired.

Here’s another solution that builds on your and is better than the last
one I suggested:

extern bool _Dummy;

#define TTRACE_IF(Area, Level, Action) \
if (TraceEnabled(Area, Level)) \
{ \
try \
{ \
Action; \
if (_Dummy) throw 0; \
} \
catch (…) \
{ \
ReportProblem(); \
} \
}

Elsewhere, define _Dummy to be initialized to false. The compiler won’t
be able to optimize out the “if (_Dummy)” (and its associated throw)
although at runtime it will always be false and no throw will actually
take place.

Chuck

----- Original Message -----
From: “Stoyan Damov”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, June 23, 2004 1:03 PM
Subject: RE: [ntdev] How to disable warning for a macro?

> And here comes the dreaded solution:)
>
> #define TTRACE_IF(Area, Level, Action) <br>> if (TraceEnabled(Area, Level)) <br>> { <br>> try <br>> { <br>> Action; <br>> int a = Area; int* p = &a; if (p) throw 0; <br>> } <br>> catch (…) <br>> { <br>> ReportProblem(); <br>> } <br>> }
>
> Voila, the warning goes away :slight_smile:
>
> 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) <br>> if (TraceEnabled(Area, Level)) { <br>> try { <br>> Action; <br>> } <br>> catch (…) { <br>> ReportProblem(); <br>> } <br>> }
>
> 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) <br>> if (TraceEnabled(Area, Level) { <br>> try { <br>> Action; <br>> } <br>> catch (…) { <br>> ReportProblem(); <br>> } <br>> }
>
> 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@cbatson.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Hi,

Have you read the follow-up to my previous mail? :slight_smile:
I said that instead “if (p)”, the code should be “if !(p)”.
It works perfectly and does not need an extern.

Cheers,
Stoyan

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Chuck Batson
Sent: Wednesday, June 23, 2004 9:27 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to disable warning for a macro?

The warning goes away, however “if (p)” will always be true, thus
throwing 0 and causing ReportProblem() to be called, which is
presumably
undesired.

Here’s another solution that builds on your and is better
than the last
one I suggested:

extern bool _Dummy;

#define TTRACE_IF(Area, Level, Action) \
if (TraceEnabled(Area, Level)) \
{ \
try \
{ \
Action; \
if (_Dummy) throw 0; \
} \
catch (…) \
{ \
ReportProblem(); \
} \
}

Elsewhere, define _Dummy to be initialized to false. The
compiler won’t
be able to optimize out the “if (_Dummy)” (and its associated throw)
although at runtime it will always be false and no throw will actually
take place.

Chuck

----- Original Message -----
From: “Stoyan Damov”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, June 23, 2004 1:03 PM
> Subject: RE: [ntdev] How to disable warning for a macro?
>
>
> > And here comes the dreaded solution:)
> >
> > #define TTRACE_IF(Area, Level, Action) <br>> > if (TraceEnabled(Area, Level)) <br>> > { <br>> > try <br>> > { <br>> > Action; <br>> > int a = Area; int* p = &a; if (p) throw 0; <br>> > } <br>> > catch (…) <br>> > { <br>> > ReportProblem(); <br>> > } <br>> > }
> >
> > Voila, the warning goes away :slight_smile:
> >
> > 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) <br>> > if (TraceEnabled(Area, Level)) { <br>> > try { <br>> > Action; <br>> > } <br>> > catch (…) { <br>> > ReportProblem(); <br>> > } <br>> > }
> >
> > 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) <br>> > if (TraceEnabled(Area, Level) { <br>> > try { <br>> > Action; <br>> > } <br>> > catch (…) { <br>> > ReportProblem(); <br>> > } <br>> > }
> >
> > 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@cbatson.com
> > 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

Ah you tried compiling with /EHac ? It should remove those warnings since it
will activate asynchronous exceptions and tell the compiler that extern C
functions can throw exceptions. There won’t be any warning anymore (if I’m
right) since the code will be actually compiled/linked.

By the way your app will be fatter and slower but isn’t what you wanted?

M-A

“Michal Vodicka” wrote in message
news:xxxxx@ntdev…
I have a trace macro which looks like this in C++ version (simplified):

#define TTRACE_IF(Area, Level, Action) <br>if (TraceEnabled(Area, Level) { <br> try { <br> Action; <br> } <br> catch (…) { <br> ReportProblem(); <br> } <br>}

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]

Oups I forgot, you have another step to make it sure it works.
You haven’t said if you compiled with the DDK or with VS.NET2003 (neither if
it’s an user or kernel app. I assume user)

If you use VS.NET2003, you have to *disable* the “Enable C++ Exceptions” in
the code generation tab in your project. And you can use /EHa instead of
/EHac if you think *no* extern c function will throw exception. Otherwise be
safe and use /EHac.

On the DDK, you can use this define instead:
USE_NATIVE_EH=1
From MSDN: “Use the US_NATIVE_EH macro if you are using standard C++
exception handling (try, catch, and throw).”

M-A

“Marc-Antoine Ruel” wrote in message news:xxxxx@ntdev…
> Ah you tried compiling with /EHac ? It should remove those warnings since
it
> will activate asynchronous exceptions and tell the compiler that extern C
> functions can throw exceptions. There won’t be any warning anymore (if I’m
> right) since the code will be actually compiled/linked.
>
> By the way your app will be fatter and slower but isn’t what you wanted?
>
> M-A
>
>
> “Michal Vodicka” wrote in message
> news:xxxxx@ntdev…
> I have a trace macro which looks like this in C++ version (simplified):
>
> #define TTRACE_IF(Area, Level, Action) <br>> if (TraceEnabled(Area, Level) { <br>> try { <br>> Action; <br>> } <br>> catch (…) { <br>> ReportProblem(); <br>> } <br>> }
>
> 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]
>
>
>

I like to declare an inline function that returns true. The compiler
sees this as a real choice when processing this warning and the code
optimizer could potentially optimize out the entire branch when it
merges the inline function into the call site.

The optimizer can’t optimize out the branch if you use a global variable
because it could be changed, and I think the analyzer will determine
that you’re trying to trick it if you declare the variable as const (not
to mention that const is meaningless since it can be casted away so I
bet the optimizer won’t care about it)

I ***believe*** I’ve successfully made the compiler do this before. I
don’t remember entirely and I don’t have time right now to do an
experiment, but you might give it a try.

-p

This posting is provided “AS IS” with no warranties, and confers no
rights.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Chuck Batson
Sent: Tuesday, June 22, 2004 11:27 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to disable warning for a macro?

The warning goes away, however “if (p)” will always be true, thus
throwing 0 and causing ReportProblem() to be called, which is presumably
undesired.

Here’s another solution that builds on your and is better than the last
one I suggested:

extern bool _Dummy;

#define TTRACE_IF(Area, Level, Action) \
if (TraceEnabled(Area, Level)) \
{ \
try \
{ \
Action; \
if (_Dummy) throw 0; \
} \
catch (…) \
{ \
ReportProblem(); \
} \
}

Elsewhere, define _Dummy to be initialized to false. The compiler won’t
be able to optimize out the “if (_Dummy)” (and its associated throw)
although at runtime it will always be false and no throw will actually
take place.

Chuck

----- Original Message -----
From: “Stoyan Damov”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, June 23, 2004 1:03 PM
Subject: RE: [ntdev] How to disable warning for a macro?

> And here comes the dreaded solution:)
>
> #define TTRACE_IF(Area, Level, Action) <br>> if (TraceEnabled(Area, Level)) <br>> { <br>> try <br>> { <br>> Action; <br>> int a = Area; int* p = &a; if (p) throw 0; <br>> } <br>> catch (…) <br>> { <br>> ReportProblem(); <br>> } <br>> }
>
> Voila, the warning goes away :slight_smile:
>
> 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) <br>> if (TraceEnabled(Area, Level)) { <br>> try { <br>> Action; <br>> } <br>> catch (…) { <br>> ReportProblem(); <br>> } <br>> }
>
> 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) <br>> if (TraceEnabled(Area, Level) { <br>> try { <br>> Action; <br>> } <br>> catch (…) { <br>> ReportProblem(); <br>> } <br>> }
>
> 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@cbatson.com
> 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@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Great! Thanks for the idea. I was stuck trying to convince compiler to not generate warning and missed the possibility to remove the warning reason. Throwing exception is too expensive but I think about calling an empty C++ function which can possibly throw anything. It should make compiler happy; inline would be the best but I doubt it would work. I’ll try and also other ideas.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Chuck Batson[SMTP:xxxxx@cbatson.com]
Reply To: Windows System Software Devs Interest List
Sent: Wednesday, June 23, 2004 6:06 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to disable warning for a macro?

If this is for debug only, try making a dummy type and throw it after
Action, like so:

struct _Dummy;

if (TraceEnabled(Area, Level)) {
try {
Action;
throw _Dummy;
}
catch (const _Dummy &) {
// do nothing
}
catch (…) {
ReportProblem();
}
}

It’s possible the compiler’s still smart enough to realize the
catch(…) will never get executed, but it’s worth a try. Downside is
throwing the _Dummy exception all the time might impact performance.

Chuck

----- Original Message -----
From: “Michal Vodicka”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, June 23, 2004 8:51 AM
> 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) <br>> > if (TraceEnabled(Area, Level) { <br>> > try { <br>> > Action; <br>> > } <br>> > catch (…) { <br>> > ReportProblem(); <br>> > } <br>> > }
> >
> > 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@cbatson.com
> > 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@upek.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Thanks for all suggestions and to all who responded. Now I’m sure problem has a solution and will try to find the best one. Will report result here. Inline function seem promising.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Peter Wieland[SMTP:xxxxx@windows.microsoft.com]
Reply To: Windows System Software Devs Interest List
Sent: Wednesday, June 23, 2004 5:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to disable warning for a macro?

I like to declare an inline function that returns true. The compiler
sees this as a real choice when processing this warning and the code
optimizer could potentially optimize out the entire branch when it
merges the inline function into the call site.

The optimizer can’t optimize out the branch if you use a global variable
because it could be changed, and I think the analyzer will determine
that you’re trying to trick it if you declare the variable as const (not
to mention that const is meaningless since it can be casted away so I
bet the optimizer won’t care about it)

I ***believe*** I’ve successfully made the compiler do this before. I
don’t remember entirely and I don’t have time right now to do an
experiment, but you might give it a try.

-p

This posting is provided “AS IS” with no warranties, and confers no
rights.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Chuck Batson
Sent: Tuesday, June 22, 2004 11:27 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to disable warning for a macro?

The warning goes away, however “if (p)” will always be true, thus
throwing 0 and causing ReportProblem() to be called, which is presumably
undesired.

Here’s another solution that builds on your and is better than the last
one I suggested:

extern bool _Dummy;

#define TTRACE_IF(Area, Level, Action) \
if (TraceEnabled(Area, Level)) \
{ \
try \
{ \
Action; \
if (_Dummy) throw 0; \
} \
catch (…) \
{ \
ReportProblem(); \
} \
}

Elsewhere, define _Dummy to be initialized to false. The compiler won’t
be able to optimize out the “if (_Dummy)” (and its associated throw)
although at runtime it will always be false and no throw will actually
take place.

Chuck

----- Original Message -----
From: “Stoyan Damov”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, June 23, 2004 1:03 PM
> Subject: RE: [ntdev] How to disable warning for a macro?
>
>
> > And here comes the dreaded solution:)
> >
> > #define TTRACE_IF(Area, Level, Action) <br>> > if (TraceEnabled(Area, Level)) <br>> > { <br>> > try <br>> > { <br>> > Action; <br>> > int a = Area; int* p = &a; if (p) throw 0; <br>> > } <br>> > catch (…) > <br>> > { <br>> > ReportProblem(); <br>> > } <br>> > }
> >
> > Voila, the warning goes away :slight_smile:
> >
> > 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) <br>> > if (TraceEnabled(Area, Level)) { <br>> > try { <br>> > Action; <br>> > } <br>> > catch (…) { <br>> > ReportProblem(); <br>> > } <br>> > }
> >
> > 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) <br>> > if (TraceEnabled(Area, Level) { <br>> > try { <br>> > Action; <br>> > } <br>> > catch (…) { <br>> > ReportProblem(); <br>> > } <br>> > }
> >
> > 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@cbatson.com
> > 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@windows.microsoft.com
> 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@upek.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Sorry but disabling C++ exceptions and enable asynchronous ones isn’t an option. Macro is used for projects which heavily use C++ exceptions. This is the way we use for error handling. Also, asynchronous exceptions would blow up and slow up the code which isn’t the goal. The goal is to have optional blocks of code depending on current trace settings.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Marc-Antoine Ruel[SMTP:xxxxx@pyxis.com]
Reply To: Windows System Software Devs Interest List
Sent: Wednesday, June 23, 2004 4:49 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to disable warning for a macro?

Oups I forgot, you have another step to make it sure it works.
You haven’t said if you compiled with the DDK or with VS.NET2003 (neither if
it’s an user or kernel app. I assume user)

If you use VS.NET2003, you have to *disable* the “Enable C++ Exceptions” in
the code generation tab in your project. And you can use /EHa instead of
/EHac if you think *no* extern c function will throw exception. Otherwise be
safe and use /EHac.

On the DDK, you can use this define instead:
USE_NATIVE_EH=1
From MSDN: “Use the US_NATIVE_EH macro if you are using standard C++
exception handling (try, catch, and throw).”

M-A

“Marc-Antoine Ruel” wrote in message news:xxxxx@ntdev…
> > Ah you tried compiling with /EHac ? It should remove those warnings since
> it
> > will activate asynchronous exceptions and tell the compiler that extern C
> > functions can throw exceptions. There won’t be any warning anymore (if I’m
> > right) since the code will be actually compiled/linked.
> >
> > By the way your app will be fatter and slower but isn’t what you wanted?
> >
> > M-A
> >
> >
> > “Michal Vodicka” wrote in message
> > news:xxxxx@ntdev…
> > I have a trace macro which looks like this in C++ version (simplified):
> >
> > #define TTRACE_IF(Area, Level, Action) <br>> > if (TraceEnabled(Area, Level) { <br>> > try { <br>> > Action; <br>> > } <br>> > catch (…) { <br>> > ReportProblem(); <br>> > } <br>> > }
> >
> > 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@upek.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Yes, Action can be any block of code including C functions and functions with throw() exception specification. It is used like this:

TTRACE_IF(TestC, TDBG_DEBUG, {
TTRACE(TdbgTest, TDBG_DEBUG, (“C support test.”));

for ( int i = 0; i < 5; ++i ) {
TestCFunction(i, _T(“C call”));
}
});

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Stoyan Damov[SMTP:xxxxx@code.bg]
Reply To: Windows System Software Devs Interest List
Sent: Wednesday, June 23, 2004 7:41 AM
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@upek.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

You missed my point. It does *not* disable C++ exceptions. But you have to
unset this flag in the project settings so the compiler doesn’t get
contradictory flags. Read the /EH documentation and you’ll understand.

Second, asynchronous was by default in VS.NET2002 (or VC6 i don’t remind
correctly; someone can confirm this?) so this is not a big deal if you
already used C++ exceptions before. Except if you make a game, I don’t think
there’s a point about not enabling asynchronous C++ exception.

Finally, you can add the compiler flag /wd4702 to completely disable the
warning if you think it is really needed. #pragma around macros are useless.

M-A

“Michal Vodicka” wrote in message
news:xxxxx@ntdev…
Sorry but disabling C++ exceptions and enable asynchronous ones isn’t an
option. Macro is used for projects which heavily use C++ exceptions. This is
the way we use for error handling. Also, asynchronous exceptions would blow
up and slow up the code which isn’t the goal. The goal is to have optional
blocks of code depending on current trace settings.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]

> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on
behalf of Marc-Antoine Ruel[SMTP:xxxxx@pyxis.com]
> Reply To: Windows System Software Devs Interest List
> Sent: Wednesday, June 23, 2004 4:49 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] How to disable warning for a macro?
>
> Oups I forgot, you have another step to make it sure it works.
> You haven’t said if you compiled with the DDK or with VS.NET2003 (neither
if
> it’s an user or kernel app. I assume user)
>
> If you use VS.NET2003, you have to disable the “Enable C++ Exceptions”
in
> the code generation tab in your project. And you can use /EHa instead of
> /EHac if you think no extern c function will throw exception. Otherwise
be
> safe and use /EHac.
>
> On the DDK, you can use this define instead:
> USE_NATIVE_EH=1
> From MSDN: “Use the US_NATIVE_EH macro if you are using standard C++
> exception handling (try, catch, and throw).”
>
> M-A
>
> “Marc-Antoine Ruel” wrote in message
news:xxxxx@ntdev…
> > Ah you tried compiling with /EHac ? It should remove those warnings
since
> it
> > will activate asynchronous exceptions and tell the compiler that extern
C
> > functions can throw exceptions. There won’t be any warning anymore (if
I’m
> > right) since the code will be actually compiled/linked.
> >
> > By the way your app will be fatter and slower but isn’t what you wanted?
> >
> > M-A
> >
> >
> > “Michal Vodicka” wrote in message
> > news:xxxxx@ntdev…
> > I have a trace macro which looks like this in C++ version (simplified):
> >
> > #define TTRACE_IF(Area, Level, Action) <br>> > if (TraceEnabled(Area, Level) { <br>> > try { <br>> > Action; <br>> > } <br>> > catch (…) { <br>> > ReportProblem(); <br>> > } <br>> > }
> >
> > 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@upek.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Marc-Antoine Ruel[SMTP:xxxxx@pyxis.com]
Reply To: Windows System Software Devs Interest List
Sent: Wednesday, June 23, 2004 8:03 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to disable warning for a macro?

You missed my point. It does *not* disable C++ exceptions. But you have to
unset this flag in the project settings so the compiler doesn’t get
contradictory flags. Read the /EH documentation and you’ll understand.

OK, I never use VS IDE so don’t know the correspondence between project settings and compiler flags. My point is I can’t change our projects exception settings just because one debug macro generates a warning. Projects settings are company wide and after such a change we’d have to test all software again.

Second, asynchronous was by default in VS.NET2002 (or VC6 i don’t remind
correctly; someone can confirm this?) so this is not a big deal if you
already used C++ exceptions before.

Nope. We never use VS defaults. Instead, our buildengine uses own settings. Similar way as DDK build/makefile.def does.

Except if you make a game, I don’t think
there’s a point about not enabling asynchronous C++ exception.

I usually work in kernel mode and use C so I’m not quite sure here. Coworker who made user mode settings told me asynchronous exceptions were disabled for two reasons. First, code size and speed. The difference is signifficant. Second, if app is written properly, asynchronous exceptions is always a bug. It is better if application crashes immediatelly in such a case because all such bugs should be fixed during testing. If there is some handler which would catch it, it can cover the bug. If exception isn’t handled, it can be trapped immediatelly by debugger at proper place. Otherwise important info may be lost.

Finally, you can add the compiler flag /wd4702 to completely disable the
warning if you think it is really needed. #pragma around macros are useless.

This is exactly what I wanted to avoid :slight_smile: The warning may be important and should be disabled only when necessary. I was looking for something like

//lint -emacro(1775, TTRACE_IF)

for lint but some of suggested tricks will solve it, too.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]

I understand your point. I didn’t thought about company wide switches.

Talking about speed, forcing the compiler to include useless code (I mean
the catch block + compiler needing to set the try block) by using tricks is
no better than getting lots of warnings. Furthermore if you force access to
dummy global variables, compared to this, async is not that bad (I have to
look at the difference in IDA Pro to further discuss on this subject).
I don’t mean I have a solution about this problem, I just mean you should
think about it twice before implementing a trick to make the compiler
include the catch block if you are caring about code size/speed. :slight_smile:

About the trapping of hard exception, you are exactly right: don’t trap what
you can’t handle. This is a problem you have since you should rethrow the
exception at the end so the exception behaviour is not changed except if you
consider the code inside the try block exception-irrelevant.

By the way, I originally thought you’d use the macro only on debug build so
I thought you could use the /wd flag in debug build (which I personally
don’t really care that much about warnings) and keep them in release builds
without this macro.

Exception-safety correctness is always an interesting and complex subject…

M-A

“Michal Vodicka” wrote in message
news:xxxxx@ntdev…
> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on
behalf of Marc-Antoine Ruel[SMTP:xxxxx@pyxis.com]
> Reply To: Windows System Software Devs Interest List
> Sent: Wednesday, June 23, 2004 8:03 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] How to disable warning for a macro?
>
> You missed my point. It does not disable C++ exceptions. But you have to
> unset this flag in the project settings so the compiler doesn’t get
> contradictory flags. Read the /EH documentation and you’ll understand.
>
OK, I never use VS IDE so don’t know the correspondence between project
settings and compiler flags. My point is I can’t change our projects
exception settings just because one debug macro generates a warning.
Projects settings are company wide and after such a change we’d have to test
all software again.

> Second, asynchronous was by default in VS.NET2002 (or VC6 i don’t remind
> correctly; someone can confirm this?) so this is not a big deal if you
> already used C++ exceptions before.
>
Nope. We never use VS defaults. Instead, our buildengine uses own settings.
Similar way as DDK build/makefile.def does.

> Except if you make a game, I don’t think
> there’s a point about not enabling asynchronous C++ exception.
>
I usually work in kernel mode and use C so I’m not quite sure here. Coworker
who made user mode settings told me asynchronous exceptions were disabled
for two reasons. First, code size and speed. The difference is signifficant.
Second, if app is written properly, asynchronous exceptions is always a bug.
It is better if application crashes immediatelly in such a case because all
such bugs should be fixed during testing. If there is some handler which
would catch it, it can cover the bug. If exception isn’t handled, it can be
trapped immediatelly by debugger at proper place. Otherwise important info
may be lost.

> Finally, you can add the compiler flag /wd4702 to completely disable the
> warning if you think it is really needed. #pragma around macros are
useless.
>
This is exactly what I wanted to avoid :slight_smile: The warning may be important and
should be disabled only when necessary. I was looking for something like

//lint -emacro(1775, TTRACE_IF)

for lint but some of suggested tricks will solve it, too.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]