[LUGOS-PROG] C debug funkcija

Dejan Markic d at blrf.net
Thu Aug 22 19:57:44 CEST 2002


#define PREFIX "%s: %s: %d: "
#define DEBUG(fmt, args...)  printf(" * DEBUG: " PREFIX fmt "\n", \
       __func__, __FILE__, __LINE__, ## args)

Tole nej bi blo po C99 standardu

torej DEBUG("Message"); ...

Lp,
Dejan
----- Original Message -----
From: "Damir Dezeljin" <programing at nib.si>
To: <lugos-prog at lugos.si>
Cc: <lugos-list at lugos.si>
Sent: Thursday, August 22, 2002 7:46 PM
Subject: [LUGOS-PROG] C debug funkcija


| Ciao.
|
| Kaj mi zna kdo svetovati kako naj bi naredil eno PORTABILNO debug
| funkcijo, ki bi delala nekaj podobnega kot sledeca (ta dela samo z GCC):
| ----
| #ifdef DEBUG
| #define DbgPrint(fmt, a...)   _DbgPrint(fmt, ## a)
| #else
| #define DbgPrint(a, b, ...)   ;
| #endif
|
| void _DbgPrint(int level, char *fmt, ...) {
|     va_list argList;
|     char timeBuffer[LEN];
|
|     va_start(argList, fmt);
|     vfprintf(stdout, fmt, argList);
|     fprintf(stdout, "\n");
|     va_end(argList);
|
|     return;
| }
| ----
|
| Vsak nasvet je dobrodosel.
|
| Imam eno idejo ... kaj pa ce stvar naredim tako:
| ----
| #ifdef DEBUG
| #define DDL 1
| #else
| #define DDL 0
| #endif
|
| void DbgPrint(int level, char *fmt, ...) {
|     do {
|         if (DDL) {
|             va_list argList;
|             char timeBuffer[LEN];
|
|             va_start(argList, fmt);
|             vfprintf(stdout, fmt, argList);
|             fprintf(stdout, "\n");
|             va_end(argList);
|             return;
|         }
|     } while(0);
| }
| ----
| Kaj v tem primeru ce ne bom kompajlal z -DDEBUG, kaj kdo ve ce so
| MS VC, HP UX, gcc ... kompajlerji dovolj 'pameteni', da bodo to funkcijo
| kar preskocli in da ne bo nic overheda? << ja vzami debugger in poglej ...
| poskusam z GDB in ne ugotovim nic pametnega ... enak rezultat imam z wdb
| na HP UX ... mogoce pa debugerja ne znam uporabljat :)
|
| Lp,
| Dezo
|
|




More information about the lugos-prog mailing list