[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



Hej

Kim Schulz 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?

GNU's compiler understøtter *variadic macros*, altså macroer med variabelt antal (og typer) parametre.

F.eks.

#define eprintf(...) fprintf (stderr, __VA_ARGS__)



eprintf("Sum %d Total %d\n", sum,total);

bliver til

fprintf(stderr, "Sum %d Total %d\n", sum,total);

Man kan også skrive

#define eprintf(args...) fprintf (stderr, args)

eller f.eks.

#define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__)

(Se bla. http://developer.apple.com/documentation/DeveloperTools/gcc-3.3/cpp/Variadic-Macros.html)


Alt det skulle virke fint, men man har et problem,hvis man skal kunne kompilere både med gnu gcc (og g++) og f.eks. Visual C++.

VC++ 6.0 understøtter ikke variadic macros, men godt variadic functions.

Er der nogen der ved, hvad man gør for at kunne kompilere både til Linux
og Windows i samme kode når man ønsker at implementere en sådan
debug print funktion som diskueret i tråden ?

--PMM
----------------------------------------------------------------
Peter Maersk-Moller
----------------------------------------------------------------
Ogg/Vorbis support for MPEG4IP. YUV12, XviD, AVI and MP4 support
for libmpeg2. See http://www.maersk-moller.net/projects/
----------------------------------------------------------------



 
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] *