Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OutputDebugString()

Posted on 2001-06-20
18
Medium Priority
?
820 Views
Last Modified: 2007-11-27
In a VC6 WinAPI program, is it necessary to enclose OutputDebugString() calls in #ifdef _DEBUG blocks, or is the function removed in release builds (like with the TRACE() macro)?

If the function call (and overhead) are not removed in release mode, then does the WinAPI or CRT provide a suitable substitute?
0
Comment
Question by:TookH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
  • +2
18 Comments
 
LVL 5

Expert Comment

by:djbusychild
ID: 6213204
the function really doesn't have to do with the "debug" mode. it simply sends strings to the debugger ( i.e. dbwin32 ) it will look for a debugger that it can hook to, if none is available it'll just not to anything. if you don't want it in your release code you should #ifdef it
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6213493
It's a fucntion (like was mentioned earlie). Usually I define another function like:

Trace(LPSTR szString)
{  
#ifndef _DEBUG
OutputDebugString(szString);
#endif
}

and I use it evrywhere in my code where I want to have some traces.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6214195
You don't HAVE to guard that, but anybodz witha tracer tool will be able to see the output.

BUT:

#ifdef _DEBUG
#define ODS( x) OutputDebugString ( x)
#else
#define ODS( x)

would do it more 'globally'...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:TookH
ID: 6216167
jkr, I like your suggestion. I'm thinking of doing something like this:

void OutputDebug( char *s, ... )
{
    va_list argList;
    char msg[256];

    va_start( argList, s );
    vsprintf( msg, s, argList);
    va_end( argList );

    OutputDebugString( msg );
}

Then I could use a macro like yours to invoke it only in debug builds. I'm not sure if it's possible to pass variable argument lists to a macro, though. Any suggestions?
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6216211
>>I'm not sure if it's possible
>>to pass variable argument lists to a macro, though. Any
>>suggestions?

Well, you cannot use variable arguments in a macro - but you can remedy the overhead in the function calls by using

void OutputDebug( char *s, ... )
{
#ifdef _DEBUG
   va_list argList;
   char msg[256];

   va_start( argList, s );
   vsprintf( msg, s, argList);
   va_end( argList );

   OutputDebugString( msg );
#endif
}

Alternatively, you could go the way e.g. MFC does:

#ifdef _DEBUG
#define OutputDebug0( psz)                  OutputDebug     ( psz)
#define OutputDebug1( psz, p1)              OutputDebug     ( psz, p1)
#define OutputDebug2( psz, p1, p2)          OutputDebug     ( psz, p1, p2)
#define OutputDebug3( psz, p1, p2, p3)      OutputDebug     ( psz, p1, p2, p3)
#define OutputDebug4( psz, p1, p2, p3, p4)  OutputDebug     ( psz, p1, p2, p3, p4)

#else   /*  ndef _DEBUG     */

#define OutputDebug0( psz)                  ( ( void) 0)
#define OutputDebug1( psz, p1)              ( ( void) 0)
#define OutputDebug2( psz, p1, p2)          ( ( void) 0)
#define OutputDebug3( psz, p1, p2, p3)      ( ( void) 0)
#define OutputDebug4( psz, p1, p2, p3, p4)  ( ( void) 0)

#endif  /*  ndef _DEBUG     */
0
 
LVL 5

Expert Comment

by:djbusychild
ID: 6216465
you could also remedby function call overhead by making it inline. Although there's no gurantee that it'll be inline.
0
 
LVL 1

Author Comment

by:TookH
ID: 6216626
I'm going to use #ifdef within the function body. If performance becomes critical, I'll switch to using the MFC method and/or djbusychild's suggestion.

Thanks everyone.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6222843
Does anyone know if this accepted answer was posted as a comment or as an answer?
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6223653
As I remember it was a comment, why you are so interested in that?
0
 
LVL 22

Expert Comment

by:nietod
ID: 6224068
We're trying to measure the number of comments vs answers.

I'm putting it down as a comment for now, if you aren't really sure, let me know (or if someone else is sure.)
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6224290
I am not really sure, it's just a guess.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6224305
Back into the "undecided" category....
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6224348
Somehow I think they (EE) probably sould remote answers at all, leave only comments. If it's not a secret, what is the proportion?
0
 
LVL 22

Expert Comment

by:nietod
ID: 6224508
Too early to tell, but currently 7 to 4--I think--in favor of comments.
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6224525
Well, one more question, what is the perpuse actually?
0
 
LVL 86

Expert Comment

by:jkr
ID: 6224626
It was a comment.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6224854
make up your minds...  :-)
0
 
LVL 1

Author Comment

by:TookH
ID: 6243155
It was a comment.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question