Need help in understanding C++ code

Discussion in 'C++' started by William.Joseph.Batson@gmail.com, Mar 15, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Mar 15, 2007
    #2
    1. Advertising

  3. Phlip Guest

    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!!!
    Phlip, Mar 15, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Need help in understanding c code

    , Jun 1, 2007, in forum: C Programming
    Replies:
    2
    Views:
    303
    Barry Schwarz
    Jun 2, 2007
  2. Daniel
    Replies:
    8
    Views:
    426
    Daniel
    Sep 13, 2007
  3. Replies:
    15
    Views:
    459
    Steven D'Aprano
    Nov 18, 2008
  4. Elmbrook

    need help understanding this code.

    Elmbrook, Sep 28, 2003, in forum: Javascript
    Replies:
    7
    Views:
    149
    Elmbrook
    Sep 29, 2003
  5. Ben
    Replies:
    6
    Views:
    106
    Tim McDaniel
    Apr 16, 2009
Loading...

Share This Page