|
From: shaunpatterson on 26 Nov 2007 10:44 Does Ada have variable length parameter lists? i.e void printf (char *, ...) Thanks
From: Steve on 26 Nov 2007 11:52 <shaunpatterson(a)gmail.com> wrote in message news:9e4ce016-d6ab-49de-b6f7-e46c59e047b1(a)t47g2000hsc.googlegroups.com... > Does Ada have variable length parameter lists? > > i.e void printf (char *, ...) No. You can achieve similar results by making a variable length array and passing the array as an parameter: type arg_array is array( Positive range <> ) of integer; procedure process_args( args : arg_array ) is begin null; end process_args; .... process_args( ( 1, 2, 3 ) ); If you need to have different argument types you can either make the elements of the array tagged or variant types. Regards, Steve (The Duck) > > Thanks
From: tmoran on 26 Nov 2007 13:44 > type arg_array is array( Positive range <> ) of integer; > > procedure process_args( args : arg_array ) is > ... > process_args( ( 1, 2, 3 ) ); If the maximum argument list is not too long, you can also use overloading, eg: procedure process_args( one : integer); procedure process_args( one, two : integer); procedure process_args( one, two, three : integer); procedure process_args( one, two, three : integer; four : character);
From: Robert A Duff on 26 Nov 2007 14:00 "Steve" <nospam_steved94(a)comcast.net> writes: > <shaunpatterson(a)gmail.com> wrote in message > news:9e4ce016-d6ab-49de-b6f7-e46c59e047b1(a)t47g2000hsc.googlegroups.com... >> Does Ada have variable length parameter lists? >> >> i.e void printf (char *, ...) > > No. > > You can achieve similar results by making a variable length array and > passing the array as an parameter: > > type arg_array is array( Positive range <> ) of integer; > > procedure process_args( args : arg_array ) is > begin > null; > end process_args; > > ... > > process_args( ( 1, 2, 3 ) ); That works fine for integers, but if you want to pass Strings (a common case), it gets rather ugly! > If you need to have different argument types you can either make the > elements of the array tagged or variant types. An array of variant records works, so long as the discriminant has a default value. As for array of tagged, well, it has to be class-wide, and array-of-class-wide is illegal, so it has to be array-of-pointer-to-class-wide. - Bob
From: axtens on 28 Nov 2007 03:48
Newbie says, "What about Stdarg.Impl?" -- $Source: /user/cp_source/ObjectAda/rts/bindings/win32ada/stdarg/ impl.ads,v $ -- $Revision: 1.1 $ $Date: 2001/01/09 19:05:19 $ $Author: shancher $ with Interfaces.C.Pointers; package Stdarg.Impl is -- ******************************************************* -- Getting arguments out of lists, for use by implementers -- of variable-parameter functions -- ******************************************************* subtype Int is Interfaces.C.Int; type Param_Access is private; function Address_of_First_Arg (Args: ArgList) return Param_Access; function Address_of_Vararg_List (Args: ArgList) return Param_Access; function ArgCount (Args: ArgList) return Int; function "&" (Left, Right: ArgList) return ArgList; procedure Do_Varargs (Proc : in System.Address; Nb_Args : Int; Arg_Addr : Param_Access); function F_Varargs (Func : in System.Address; Nb_Args : Int; Arg_Addr : Param_Access) return Stdarg.C_Param; -- debugging -- procedure Dump(Addr: Param_Access; Nb_Args : Stdarg.Int); -- pragma Import(C, Dump, "dump"); private package Arith is new Interfaces.C.Pointers( Integer, C_Param, Stdarg.ArgVector, 0); type Param_Access is new Arith.Pointer; pragma Import(C, Do_Varargs, "do_varargs"); pragma Import(C, F_Varargs, "do_varargs"); ------------------------------------------------------------------------------- -- -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR -- PURPOSE. The user assumes the entire risk as to the accuracy and the -- use of this file. -- -- Copyright (c) Intermetrics, Inc. 1995 -- Royalty-free, unlimited, worldwide, non-exclusive use, modification, -- reproduction and further distribution of this file is permitted. -- ------------------------------------------------------------------------------- end Stdarg.Impl; Kind regards, Bruce. |