🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #3359

Re: Variabel Parameters...

#3359
From: Dmitry V. Leskov
Date: Sat, 09 Mar 1996 08:47
40 lines
1788 bytes
cz@ecn.net.au wrote:

> I am wondering if it is possible, in m2, to have a procedure that can
>be called with an un-defined number of parameters, with un-defined
>types (defined ofcourse when the proc is called)... i.e for use with
>porting the printf() function in C over to modula-2...

It's not possible in the 'standard' language. Some implementations provide
extensions to the languages (XDS) or can be deceived using pragmae and code
procedures (TopSpeed).

Here's an XDS example:

<*+ m2extensions *>                -- turn language extensions ON
DEFINITION MODULE FormStr;

IMPORT  SYSTEM;

PROCEDURE print (VAR str: ARRAY OF CHAR;   -- This procedure works like ANSI C 
                     fmt: ARRAY OF CHAR;   -- sprintf function
                 SEQ arg: SYSTEM.BYTE);


In TopSpeed, you should write:

(*# save, call(var_arg => on, c_conv => on) *)
(*# call(reg_param => (), o_a_copy => off)  *)

PROCEDURE print(VAR str: ARRAY OF CHAR;
                    fmt: ARRAY OF CHAR);

(*# restore *)

and do some tricks in the implementation.

======================================================================
Dmitry V. Leskov                      Institute of Informatics Systems
Programmer                                         Novosibirsk, Russia

snowman@iis.nsk.su
Technical Details
Message-ID: <DnzsEF.2sL@itfs.nsk.su>
Path: arc1-ca.pugleaf.net!news.spb.su!KremlSun!fagot!tsiren!usenet
References: <4hodo7$flm@sydney1.world.net>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.modula2
Path: arc1-ca.pugleaf.net!news.spb.su!KremlSun!fagot!tsiren!usenet
From: snowman@iis.nsk.su (Dmitry V. Leskov)
Subject: Re: Variabel Parameters...
X-Newsreader: Forte Free Agent 1.0.82
Sender: usenet@itfs.nsk.su (Igor V. Shabalnikov)
Organization: Ershov Institute of Informatics Systems
Message-ID: <DnzsEF.2sL@itfs.nsk.su>
References: <4hodo7$flm@sydney1.world.net>
X-Nntp-Posting-Host: 194.226.177.129
Date: Sat, 9 Mar 1996 08:47:16 GMT