gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Design philosophy - why use a VAR for a single return value?


From: Benjamin Kowarsch
Subject: Re: Design philosophy - why use a VAR for a single return value?
Date: Sat, 23 Mar 2024 08:22:11 +0900

Also, back in the days of Pascal and Modula-2 it was quite common that functions could not return larger data structures, for examples arrays and records were not allowed as function return types. This was never formally specified, so it was up the compiler implementor to decide what types a function can return.

Open arrays also cannot be returned as function results.

Thus when writing portable code across dialects and compilers, you need to use VAR to pass arguments back to the caller for anything that is not a simple type, especially open arrays.

regards
benjamin

On Sat, 23 Mar 2024 at 08:16, Benjamin Kowarsch <trijezdci@gmail.com> wrote:


On Sat, 23 Mar 2024 at 07:51, Alice Osako <alicetrillianosako@gmail.com> wrote:
I am changing the API for CardBitOps to eliminate all VAR parameters for any case where only a single value is returned.

I am baffled as to why the original design used them in the first place, and dealing with that bad design decision was driving me up the wall.

In a parameter list, VAR is for passing by reference.

Unfortunately, neither PIM nor ISO provide pass by immutable reference.

We fixed this flaw in M2R10 by adding CONST for passing by immutable reference.

The reason why you may want to use VAR is efficiency, since passing a pointer is faster than copying a larger data structure.

regards
benjamin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]