2012-04-03 4 views
0

In unserem plattformübergreifende C-Projekt, das wir das Makro für die Protokollierung verwenden:Debuggen Makrodefinition in Cross-Plattform-Projekt

#if _WINDOWS 
    #define DEBUG_PRINTF(x) KdPrint(x) 
#endif 

Das DEBUG_PRINTF Verwendungsbeispiel:

DEBUG_PRINTF(("Message with param (%s)\n", pString)); //   (1) 
DEBUG_PRINTF(("Message with no param\n")); //      (2) 

Es ist OK. Nach dem KdPrint function reference ein Aufruf an KdPrint erfordert doppelte Klammern:

KdPrint ((Format, arguments)) 
KdPrintEx ((DPFLTR_DEFAULT_ID, DPFLTR_INFO_LEVEL, Format, arguments)) 

Meine Frage ist, wie zu behandeln gab es bereits Makros wie (1) und (2) durch die DEBUG_PRINTF auf andere Plattform portieren wie Linux in User-Space?

Zum Beispiel die Definition

#if defined (__LINUX__) 
    #define DEBUG_PRINTF((x)) fprintf(stderr, x) 
#endif 

nicht für Makros wie (1) nicht kompiliert.

Antwort

2

Ich würde es anders tun um:

#if _WINDOWS 
    #define DEBUG_PRINTF(x) KdPrint((x)) 
#else 
    #define DEBUG_PRINTF(format, ...) fprintf(stderr, format, ##__VA_ARGS__) 
#endif 

Verbrauch:

DEBUG_PRINTF("Message with param (%s)\n", pString); 
+0

ich getan habe, wie Sie es tun) –