Hello all,
This is something I've been vaguely aware of for a while, but now
(as I'm working on cleaning up gretl's internal handling of
user-defined variables) I've become acutely aware of it.
The "sprintf" command in gretl has a deplorable sloppiness. If you
do this
<hansl>
scalar x = 73
sprintf strvar "%g", x
</hansl>
gretl will not complain, and will create a string variable by the
name of "strvar" holding the string "73".
Further, if you do this
<hansl>
scalar x = 73
matrix strvar = I(3)
sprintf strvar "%g", x
</hansl>
gretl will still not complain, and again will add a string variable
called "strvar", which will never be seen since it is masked by a
pre-existing matrix variable of the same name.
Time for this madness to stop!
It won't be fixed in the forthcoming 1.9.10 release, but it will be
in 1.9.11: by that time, "sprintf" will expect its first argument to
name a pre-existing string variable into which to write its output,
and it will fail if there's no such variable.
<hansl>
# this is the right way!
scalar x = 73
string strvar
sprintf strvar "%g", x
print strvar
</hansl>
Allin Cottrell
Show replies by thread