On 27 Apr 2010, at 23:21, Seth Grover wrote:

> So basically I have a type defined as a dynamic array of characters,
> which I fill with some data. If I have a function which takes a
> parameter which is a "var array of char" into which I pass a variable
> of my dynamic array type it works fine. However, if I have a function
> where the parameter is an "out array of char", I get a crash when I
> try to pass in my variable.
> 
> Is this behavior correct?

No.

> Can someone explain this to me?

The compiler should simply refuse to compile your program. Both procedure calls 
are wrong. You cannot (should not be able to) pass a dynamic array as a var/out 
parameter to an open array. The declarations of the procedures that Graeme 
posted are correct (in that case, the parameter types are dynamic arrays rather 
than open arrays).

And before we get another endless discussion: yes, it is confusing/unfortunate 
that the declarations for dynamic arrays and open arrays are identical and that 
"array of byte" means something completely different depending on whether it's 
used to define a variable or type (dynamic array) or a parameter (open array).

> I thought
> that the only difference between "var" and "out" was whether or not
> the compiler warned you about uninitialized data.

It is not. In case of reference counted data, "out" parameters are finalised 
prior to calling the routine (reason: "out" was introduced by Delphi for COM 
interoperability, which mandates this behaviour). That may be part of the 
reason why the crash occurs, but I'm not sure. It doesn't matter however, since 
as mentioned above the compiler should refuse the code.


Jonas_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to