Need help in understanding C++ code

  • Thread starter William.Joseph.Batson
  • Start date
W

William.Joseph.Batson

Hi,

I found the following c++ code, but I need help in understand what it
is trying to do:
if the caller does this
DPRINTF(D_MINI_FS, ("CHXMiniFileSystem()\n"));

what will happen according to the following macro?


extern void dprintf( const char *, ... )
#ifdef __GNUC__
__attribute__((format(printf,1,2)))
#endif /* __GNUC__ */
;
extern void dprintfx( const char *, ... )
#ifdef __GNUC__
__attribute__((format(printf,1,2)))
#endif /* __GNUC__ */
;

#ifdef DEVEL_DEBUG
#define DPRINTF(mask,x) if (debug_level() & (mask)) { \
dprintf("%s:%d ", __FILE__, __LINE__); dprintfx x; } else
#else
#define DPRINTF(mask,x) if (debug_level() & (mask)) dprintf x; else
#endif /* DEVEL_DEBUG */
 
V

Victor Bazarov

Hi,

I found the following c++ code, but I need help in understand what it
is trying to do:
if the caller does this
DPRINTF(D_MINI_FS, ("CHXMiniFileSystem()\n"));

what will happen according to the following macro?


extern void dprintf( const char *, ... )
#ifdef __GNUC__
__attribute__((format(printf,1,2)))
#endif /* __GNUC__ */
;
extern void dprintfx( const char *, ... )
#ifdef __GNUC__
__attribute__((format(printf,1,2)))
#endif /* __GNUC__ */
;

#ifdef DEVEL_DEBUG
#define DPRINTF(mask,x) if (debug_level() & (mask)) { \
dprintf("%s:%d ", __FILE__, __LINE__); dprintfx x; } else
#else
#define DPRINTF(mask,x) if (debug_level() & (mask)) dprintf x; else
#endif /* DEVEL_DEBUG */

Put it in a file, compile it while retaining preprocessor output
and you will see. To rephrase, a compilation result on your machine
is worth a thousand newsgroup posts with explanations.

V
 
P

Phlip

William.Joseph.Batson said:
I found the following c++ code, but I need help in understand what it
is trying to do:

This is C code. Even if a C++ compiler could compile it, if it _could_
compile with a C compiler, then we better call it C.
if the caller does this
DPRINTF(D_MINI_FS, ("CHXMiniFileSystem()\n"));

what will happen according to the following macro?

Roughly, if debugging is turned on for this system, it will print the file
name, line number, and an arbitrary number of arguments, as a printf()
string.

If your compiler is not GNU C, the system gives up and doesn't print the
arbitrary set of arguments, because the system uses format() and does not
expect it to exist on other systems.

Note that most of the stuff here is non-Standard, meaning questions about it
will get the best answer on a GNU C forum.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top