[fpc-devel] va(r)_arg vs open array

Marco van de Voort marcov at stack.nl
Mon Oct 2 17:15:10 CEST 2006


> On 10/2/06, Dani?l Mantione <daniel.mantione at freepascal.org> wrote:
> >
> > Syntactically you cannot. However, the array of const is just as powerfull
> > (actually more powerfull, since you can pass multiple arrays). We consider
> > adding a trick to make it syntactically behave like writeln unnecessary.
> 
> But in vtype I can't know if I got array or not, and I can't know if
> that's a record. :(

You can't in C either. C varargs everything is "if string and arguments
match it won't crash".

> > > to make it possible to add such feature to FPC ?
> >
> > Show the problem with array if const first :)
> 
> Lets start from the pity ones to the real problems :)
> 
> 1. It's not a va_args.

So? Other language, other syntax. We don't use {} either.

> 2. The usage of [].

Same. Penalty for being safe. It is also required being able to mix non
array of const and normal parameters.

> 3. Even empty parameter must have [] instead of not calling it. It's
> like C that must have empty () when calling a function ...

C has no checking what so ever, we want to do better.

> 4. I can't add default values to that type of parameter.

Can you in C?

> 5. Feel like an hack.

Where do you get that feeling?

> 6. Try to explain that to a C developer... it easier to bash your head
> against the wall

Then don't do it. Let the C runtime solve his interface problem for him, and
only provide (2) calls.

> 7. Require delphi/objfpc modes.

So? It is higher level functionality.

> 8. Have a record inside that tells you the type of the parameter (that
> is also a pro as much as it con)

Only on the inside. Your application programmer won't notice this.

> 9. I feel like it limiting the type of usage I can do with it because it
> support only "basic" types of parameters (according to the example in the
> documentation:
> http://www.freepascal.org/docs-html/ref/refsu47.html#x113-12000010.3.6).

You can pass any class, and, after verifying it is a class, further
discriminate using object.classtype and/or is/as operators

> 10. I feel that there is not enough documentation about it.

Look for "Essential Pascal".

> There might be probably more reasons why not to use open arrays, but I
> can't think on more at the moment.

Basically all are "it is not both C and Java". Well, it isn't. It is
FPC/Delphi.

Even if you want to make a comparison, make one, and then also list the
disadvantages of the solution (like the horrible security model of C, or the
runtime overhead of Java)



More information about the fpc-devel mailing list