On 24 December 2009 10:48, James Paige <[email protected]> wrote:
> On Thu, Dec 24, 2009 at 03:59:15AM +1300, Ralph Versteegen wrote:
>> I am now sure that defaulting to BYREF is pure evil, and we should
>> make OPTION BYVAL a priority. Plus, I'm getting sick of typing
>> hundreds of explicit BYVALs.
>
> I like that goal. I have been making an effort to be explicit about
> integer arguments already.
>
> I was reading the FreeBasic docs about BYVAL and OPTION BYVAL, and I am
> uncertain about a couple things.
>
> A BYVAL default for integers and ptrs is a no-brainer, and I understand
> the quirks regarding BYVAL strings, but what I don't know is:
>
> * Does BYVAL on a TYPE make a complete copy of the whole dang structure?
Yes.
> * Does OPTION BYVAL apply to TYPEs?
No. The BYVAL doc page says (and I just tested that -lang deprecated +
option explicit behaves identically to -lang fb):
Dialect Differences:
* In the -lang fb dialect, Byval is the default parameter passing
convention for all built-in types except String; String and
user-defined Types are passed Byref by default.
* In -lang qb and -lang fblite dialects, Byref is the default
parameter passing convention.
> * What effect (if any) does BYVAL have on arrays?
Arrays can't be passed BYVAL.
> * Does OPTION BYVAL apply to arrays?
>
> ---
> James Paige
Also, I missed this the first time, very important: byval strings are
the same as zstrings (not zstring ptrs)! Modifying them will compile
and probably work, but if you make the string too long, you'll write
past the end of allocated memory. We use byval strings in a lot of
places! We should remove them all; the docs recommend that there's
really no need to ever use byval strings: either use strings or
zstring ptrs.
_______________________________________________
Ohrrpgce mailing list
[email protected]
http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org