On Fri, Mar 15, 2019 at 7:02 AM Artur Tarassow <atecon(a)posteo.de> wrote:
Dear all,
the following example crashes using latest git on ubuntu 18.10 with an
error:
<Speicherzugriffsfehler (Speicherabzug geschrieben)> aka 'memory access
violation'
<hansl>
clear
set verbose off
function bundle default_naiveFC_opts (const series y)
# Set default values
bundle self = null
self.h = 10 # forecast horizon
return self
end function
function bundle naiveFC (const series y,
string which "Select method",
bundle opts[null])
# Set up the bundle
bundle self = default_naiveFC_opts(y)
if exists(opts)
# override defaults
self = opts + self
endif
series self.y = y
# call method
if which=="meanf"
self.fc = meanf(&self) # !!! fails with a crash !!!
#self.fc = meanf2(&self) # works
endif
return self
end function
function matrix meanf2 (bundle *self)
return ones(self.h, 1) .* mean(self.y)
end function
function void meanf (bundle *self)
self.fc = ones(self.h, 1) .* mean(self.y)
eval self.fc
end function
# Example
open nysewk.gdt -q
bundle b = naiveFC(close, "meanf")
</hansl>
Gretl shouldn't crash, but there's a rather obvious bug in your code:
you are assigning
to self.fc from a function (meanf) that doesn't return anything. In
general gretl should be
be able to catch that bug. I guess the problem in this case is that
gretl has no means of
knowing what type of return value is wanted: "self.fc" carries no type
information.
I'd usually say, expect a fix real soon, but my internet access will
be limited till Monday
so I may not come up with a fix before then.
Allin