[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] [C] debug udprint funktion ala printf



On Thu, 20 Nov 2003 10:58:08 +0100
Kim Schulz <sslug@sslug> wrote:

> hejsa
> jeg sidder og mangler en debug funktion der virker som printf (altså man
> kan samle en streng af X parametre). Det er meningen at det skal kunne
> slået til og fra via f.eks. en define. 
> Nogen der ligger inde med en sådanne, eller kan give et hint til hvordan
> det kan laves?

int nullprintf(const char * format, ...) { return 0 ; }

#if defined DBGP
#define debugp printf
#else
#define debugp nullprintf
#endif

Det er noget i den stil, som Rasmus Andersen foreslår. Der er to
problemer, eller svagheder, 

  1. du kommer til at betale med et functioncall når du ikke debugger.

  2. du bruger preprocessoren, hvilket af mange årsager er knap så heldigt.

Så her kommer GCC med inline handy ind

inline int nullprintf(const char * format, ...) { return 0 ; }

vil erstatte debugp med et statement 0;

===================================================
/*debug w/o cost? */

#include <stdio.h>

inline int nullprintf(const char * format, ...) { return 0 ; }

#if defined DBGP
#define debugp printf
#else
#define debugp nullprintf
#endif

int mm(char *x)
{
    debugp("ddt:%s\n",x);
    return 0;
}

===================================================

Uddrag af oversættelse med kommentar:

mm:
        pushl   %ebp
        movl    %esp, %ebp
        movl    $0, %eax
        popl    %ebp
        ret
        .size   mm, .-mm
.globl nullprintf
        .type   nullprintf, @function
nullprintf:
        pushl   %ebp
        movl    %esp, %ebp
        movl    $0, %eax            <-- ingen print, ingenting.
        popl    %ebp
        ret
        .size   nullprintf, .-nullprintf
        .ident  "GCC: (GNU) 3.3.1"




-- 
sslug@sslug -- http://d-axel.dk/


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:10 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *