Jump to content

Variadic function: Difference between revisions

m
→‎[[Varargs#ALGOL 68]]: removed printf, space and new page procedure as these are not in ELLA and can be moved without detracting from the code sample.
No edit summary
m (→‎[[Varargs#ALGOL 68]]: removed printf, space and new page procedure as these are not in ELLA and can be moved without detracting from the code sample.)
Line 15:
''However'' a flexible array of tagged types (union) <u>is</u> permitted. This effectively
allows the passing of strongly typed variable arguments to procedures.
 
MODE STRINT = UNION(STRING, INT, PROC(REF FILE)VOID, VOID);
{{works with|ALGOL 68|Standard - no extensions to language used}}
PROC print strint = (FLEX[]STRINT argv)VOID: (
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
FOR i TO UPB argv DO
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386}}
CASE argv[i] IN
<pre>
(INT i):printf(($d$,i)),
main:(
(STRING s):print(s),
MODE STRINT = UNION(STRING, INT, (PROC(REF FILE)VOID, fVOID):f(stand out),;
 
(VOID):print(error char) # print a "*" #
PROC print strint = (FLEX[]STRINT argv)VOID: (
ESAC;
IFFOR i NETO UPB argv THEN print((space)) FIDO
FOR i TO UPBCASE argv[i] DOIN
OD
(INT i):printfprint(whole($d$,i,-1)),
);
(STRING s):print(s),
print strint((new page, "Mary", "had", 1, "little", EMPTY, "...", new line))
(PROC(REF FILE)VOID f):f(stand out),
(VOID):print(error char) # print a "*" #
ESAC;
IF i NE UPB argv THEN print((" ")) FI
OD
);
 
print strint((new page, "Mary", "had", 1, "little", EMPTY, "...", new line))
)
</pre>
Output:
<pre>
<newpage>
Mary had 1 little * ...
</pre>
Also note that EMPTY (of type VOID) can be used to indicate missing or optional arguments.
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.