Funktionen mit beliebig vielen Parametern: Wie?

Post Reply
Message
Author
Don Philippe
Posts: 8
Joined: 14. May 2004 14:38

Funktionen mit beliebig vielen Parametern: Wie?

#1 Post by Don Philippe »

Ich habe leider im Netzt nichts gefunden.

Wie mache Ich Funktionen, denen Ich beliebig viele Parameter übergeben kann?
(Zum beispiel wie bei printf...)


Vielen Dank im Vorraus

Don Philippe

Entfernt
Posts: 149
Joined: 22. Jul 1999 12:53

#2 Post by Entfernt »

Deklaration:

Code: Select all

typ bezeichner(typ var1, typ var2, ...);
Die Punkte lassen beliebig viele Parameter zu. Wie man darauf zugreift steht inclusive Beispiel in der Manpage va_arg

JochenAlsGast

#3 Post by JochenAlsGast »

Die Man-Page findet man auch unter dem Begriff "stdarg"; "stdarg.h" ist das Include-File, dass Du dazu einbinden musst.

Solltest Du irgendwo noch über "varargs.h" stolpern, schnell vergessen bzw. umschreiben, weil das die veraltete, nicht standardkonforme Version ist.

Jochen

Gast

Hier ist ein Beispiel

#4 Post by Gast »

int pvPrintf(PARAM *p, int id, const char *format, ...)
{
char text[MAX_PRINTF_LENGTH+40];

va_list ap;
va_start(ap,format);
#ifdef _WIN32
_vsnprintf(text, MAX_PRINTF_LENGTH - 1, format, ap);
#endif
#ifdef __VMS
vsprintf(text, format, ap);
#endif
#ifdef unix
vsnprintf(text, MAX_PRINTF_LENGTH - 1, format, ap);
#endif
va_end(ap);

pvSetText(p,id,text);
return 0;
}

Tom2

#5 Post by Tom2 »

Funktionsname(Typ1 *a1, int na1, Typ2 *a2, int na2, ...)
[/code]

squeez
Posts: 9
Joined: 24. Jun 2004 17:05
Location: CH
Contact:

#6 Post by squeez »

tach

Hier gibts ein Tutorial dazu:
http://pronix.de/modules/C/openbook/c_p ... ung_21.php

greetz by
squeez

Don Philippe
Posts: 8
Joined: 14. May 2004 14:38

#7 Post by Don Philippe »

Danke! 8)

Post Reply