comp.lang.ada
 help / color / mirror / Atom feed
* Variable list parameters
@ 2007-11-26 15:44 shaunpatterson
  2007-11-26 16:52 ` Steve
  0 siblings, 1 reply; 6+ messages in thread
From: shaunpatterson @ 2007-11-26 15:44 UTC (permalink / raw)


Does Ada have variable length parameter lists?

i.e  void printf (char *, ...)

Thanks



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Variable list parameters
  2007-11-26 15:44 Variable list parameters shaunpatterson
@ 2007-11-26 16:52 ` Steve
  2007-11-26 18:44   ` tmoran
  2007-11-26 19:00   ` Robert A Duff
  0 siblings, 2 replies; 6+ messages in thread
From: Steve @ 2007-11-26 16:52 UTC (permalink / raw)


<shaunpatterson@gmail.com> wrote in message 
news:9e4ce016-d6ab-49de-b6f7-e46c59e047b1@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 





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Variable list parameters
  2007-11-26 16:52 ` Steve
@ 2007-11-26 18:44   ` tmoran
  2007-11-26 19:00   ` Robert A Duff
  1 sibling, 0 replies; 6+ messages in thread
From: tmoran @ 2007-11-26 18:44 UTC (permalink / raw)


>  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);



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Variable list parameters
  2007-11-26 16:52 ` Steve
  2007-11-26 18:44   ` tmoran
@ 2007-11-26 19:00   ` Robert A Duff
  2007-11-28  8:48     ` axtens
  1 sibling, 1 reply; 6+ messages in thread
From: Robert A Duff @ 2007-11-26 19:00 UTC (permalink / raw)


"Steve" <nospam_steved94@comcast.net> writes:

> <shaunpatterson@gmail.com> wrote in message 
> news:9e4ce016-d6ab-49de-b6f7-e46c59e047b1@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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Variable list parameters
  2007-11-26 19:00   ` Robert A Duff
@ 2007-11-28  8:48     ` axtens
  2007-11-28 20:21       ` amado.alves
  0 siblings, 1 reply; 6+ messages in thread
From: axtens @ 2007-11-28  8:48 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Variable list parameters
  2007-11-28  8:48     ` axtens
@ 2007-11-28 20:21       ` amado.alves
  0 siblings, 0 replies; 6+ messages in thread
From: amado.alves @ 2007-11-28 20:21 UTC (permalink / raw)


Stdarg.Impl looks like support to import C units that have a variable
number of arguments.

Programming in Ada you should use one of the idioms already mentioned.

(Don't try to write C in Ada. You'll only hurt yourself.)



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-11-28 20:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-26 15:44 Variable list parameters shaunpatterson
2007-11-26 16:52 ` Steve
2007-11-26 18:44   ` tmoran
2007-11-26 19:00   ` Robert A Duff
2007-11-28  8:48     ` axtens
2007-11-28 20:21       ` amado.alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox