2010年11月1日 星期一

Auto fill function name

/*----------------------------------------------------
*/
/* This file try auto fill funciton name in the begin of debug 20090703 smo
*/
/* Key word: __VA_ARGS__         
*/
/*------------------------------------------------------
*/

#include <stdio.h>
#include <stdarg.h>

/*if no ##, there must be one argument at least. */
#define mldsnppxyFuncPrint(a,...) mldsnppxyDbg(__PRETTY_FUNCTION__,a,##__VA_ARGS__)

int mldsnppxyDbg(char* funcName,char* format,...)
{
    char buffer[256];
    printf("@%s: ",funcName);
    va_list args;
    va_start (args, format);
    vsprintf (buffer,format, args);
    printf (buffer);
    va_end (args);
    return 0;
}

int main()
{
    int testInt=3;
    char testStr[]="smo";
    mldsnppxyFuncPrint("int =%d, string= %s\n\n",testInt,testStr);   
    return 0;
}

沒有留言:

張貼留言