Check for SYS/GL during library init. Reason is that
[AROS.git] / test / sdi / examples / varargs / example_varargs.c
blob2084adcd5c866e11044d108ab3b518e149bec499
1 /* Example source
3 Name: example_varargs.c
4 Versionstring: $VER: example_varargs.c 1.0 (06.10.2004)
5 Author: Jens Langner
6 Distribution: PD
7 Description: shows how the SDI_stdarg.h header include are used
9 1.0 06.10.04 : initial version showing how the SDI_stdarg.h header have to be
10 used if one wants to keep the sources platform independent
11 throughout all common AmigaOS compatible platforms like OS3,
12 OS4 and MorphOS, because all of those systems have a slightly
13 different way to deal with variable argument functions.
16 Please note that this example is just for educational purposes and wasn't
17 checked for complete correctness. However, it should compile and probably also
18 work as expected. But please note that its purpose is to show how the varargs
19 macros make it very easy to deal with variable argument based functions and also
20 keep the sources simple and platform independent through OS3, OS4 and MorphOS.
22 Feel free to comment and submit any suggestions directly to
23 Jens.Langner@light-speed.de
27 #include <proto/exec.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string.h>
33 #include "SDI_stdarg.h"
35 /******************************************************************************/
36 /* Example of a variable argument based function which is automatically */
37 /* compatible to varargs definitions of AmigaOS3, AmigaOS4 and MorphOS... */
38 /******************************************************************************/
40 static int STDARGS VARARGS68K MySPrintf(char *buf, char *fmt, ...)
42 VA_LIST args;
44 VA_START(args, fmt);
45 vsprintf(buf, fmt, args);
46 VA_END(args);
48 return(strlen(buf));
51 /******************************************************************************/
52 /* The main entry point to just illustrate how the varargs function is called */
53 /******************************************************************************/
55 int main(void)
57 char buf[256];
58 char *type = "portable varargs";
59 LONG ret;
61 ret = MySPrintf(buf, "This is a '%s' function", type);
63 printf("%s returning %d\n", buf, (int)ret);
65 return 0;