By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

Need help in understanding C++ code

P: n/a
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 */

Mar 15 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Wi*******************@gmail.com wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 15 '07 #2

P: n/a
William.Joseph.Batson wrote:
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.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Mar 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.