[fpc-devel] Question on constref

Steve Litt slitt at troubleshooters.com
Wed Feb 1 12:40:11 CET 2023


Bart via fpc-devel said on Wed, 1 Feb 2023 11:30:37 +0100

>Hi,
>

>The function is not supposed to alter the contents of this
>datastructure. So, I need to pass this structure by reference.
>(I've spent hours and hours looking at unexpected results in my
>program because I passed the datastructure by value, so the returned
>pointer was in fact garbage...)

I haven't done much Pascal programming this century, but in my C
programming, regardless of the way the structure is passed in, the
returned pointer shouldn't be garbage unless either:

* You're returning a local pointer that goes out of scope outside the
  function, or,

* There's an error inside your function.

You could deduce which by looking at the contents of the pointer just
before your function ends. If it's garbage, your function has an error.
If not, check to see if you're returning a pointer that's a local
variable, because in C at least, doing so causes problems: Often
intermittent problems.

SteveT

Steve Litt 
Autumn 2022 featured book: Thriving in Tough Times
http://www.troubleshooters.com/bookstore/thrive.htm


More information about the fpc-devel mailing list