macro taking variable args

Discussion in 'Windows Vista Drivers' started by tsindia, Apr 6, 2006.

  1. tsindia

    tsindia Guest

    Hi ,

    ISO C defines macros that can take variable arguments. The code below
    compiles on linux but fails with DDK XP. Do I have a similar option in

    #define AMZ_OSAL_debug1(format, ...) \



    "DEBUG LOG %s, line-%d%::", __FILE__, __LINE__ ));\


    format, __VA_ARGS__ ));\





    tsindia, Apr 6, 2006
    1. Advertisements

  2. Microsoft uses va_list.

    Try looking in the headers as this is too simple and so much faster than
    trying to learn via email or newsgroups.
    David J. Craig, Apr 6, 2006
    1. Advertisements

  3. tsindia

    tsindia Guest

    Hi David,

    Yes, I had defined an inline function to use va_list which was working
    fine. The problem is that I am trying to print the file name and the line
    number of the debug message, but it prints the file name and teh line number
    of the debug function and not where the debug message is actually occcuring.
    That's why i was trying to use a macro instead of a function using va_list.
    Sorry to bother you if my question is stupid. The inline function I am
    talking of is defined as below:

    __inline void AMZ_OSAL_debug1(char *msg_fmt, ...)


    char msg_buffer[MSG_LEN];

    va_list arg_list;


    "DEBUG LOG %s, line-%d%::", __FILE__, __LINE__ ));

    va_start( arg_list, msg_fmt );

    RtlStringCbVPrintfA(msg_buffer, MSG_LEN, msg_fmt,arg_list);



    "%s\n", msg_buffer));



    I hope you will realise that this won't print the file name and the line
    number that i wish it to print.

    tsindia, Apr 6, 2006
  4. tsindia

    Mark Roddy Guest

    msoft C does not support vararg macros. You can simulate varargs by
    wrapping the arguments in parenthesis on invocation.
    Mark Roddy, Apr 6, 2006
  5. tsindia

    Pavel A. Guest

    Ntoskrnl exports two vararg versions of DebugPrint:
    vDbfPrintEx and vDbgPrintExWithPrefix.
    They will do what you want.
    But... these are not documented. The prototypes however are in wdm.h.

    Pavel A., Apr 6, 2006
  6. variadic macros is a C99 spec feature which was only recently approved in
    the last couple of years. The XP DDK was released before the spec was

    Doron Holan [MS], Apr 7, 2006
  7. tsindia

    Tim Roberts Guest

    Actually, much to my surprise, VC++ 8.0 does, exactly as he describes.
    Howver, the 3790.1830 DDK includes VC++ 7.1, which does not.

    The current WDK includes VC++ 8.0, so the __VA_ARGS__ thing will work.
    Unfortunately, it's only in beta.

    That exact code works in VC++ 8.0. The OP is just a bit ahead of his time.
    Tim Roberts, Apr 7, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.