Talk:Plan for sane script error reporting

Jump to: navigation, search
> get rid of the command name string arguments to functions like valid_plotslice
> (I'd like to mention that passing string literals to functions which don't use
> them is very expensive in FB, this isn't C!) 

Bob the Hamster: Wouldn't a quick way to minimize this problem be to declare those arguments BYREF?

The Mad Cacti: I just investigated. BYREF makes no difference, it is the default string passing method (for both -lang fb and -lang deprecated). It's BYVAL which causes strings to be passed as C-style zstrings. However actually using this is risky, this code corrupts memory if you pass it a string without a large enough buffer (eg, any literal):

SUB mysub (byval a as string)
  a += "foo"

I assume the reason it does this is because as soon as you use C-style strings, FB starts expecting you, a C programmer, to do all the work yourself. += here acts like strcat, wrapped by a whole lot of functions that don't actually provide much added value.

Writing that C++ string wrapper is so much work. There are many many apparently redundant string functions in the rtlib, and some of the ones the compiler calls are the wrong one to use. I need to find a balance between responsibly using the public functions provided, or calling whichever (possibly private) function looks more straightforward.

Anyway, it seems that passing literals is not as expensive as I thought since the temporary string descriptor is created on the stack, not the heap. The rest of the interpreter is slow enough to totally dwarf it. However lots of string manipulation seems to be part of bug 707.