Discussion:
String_Type is really an integer :/
(too old to reply)
Lars Stokholm
2005-01-13 13:35:49 UTC
Permalink
I have defined this array in some slrn macro:

variable strings = String_Type [1];

This does what it's supposed to:

() = sscanf (line, "%*[^|]|%[^|]|%*[^|]|%*[^|]", &testvar);
strings[0] = testvar;
() = fputs (strings[0], s_sig);

It reads a string into testvar, copies it to strings[0] and
writes strings[0] into the s_sig file.

I should think that this would essentially do the same thing:

() = sscanf (line, "%*[^|]|%[^|]|%*[^|]|%*[^|]", &strings[0]);
() = fputs (strings[0], s_sig);

But it doesn't. I get this error: "S-Lang Error: Type Mismatch:
Unable to typecast Integer_Type to String_Type".

It seems that strings[0] is an integer. Why? What's wrong?
John E. Davis
2005-01-14 05:38:56 UTC
Permalink
Post by Lars Stokholm
() = sscanf (line, "%*[^|]|%[^|]|%*[^|]|%*[^|]", &strings[0]);
() = fputs (strings[0], s_sig);
Unable to typecast Integer_Type to String_Type".
The problem is that &strings[0] is not the same as &(strings[0]).
Rather it is (&strings)[0], which is just &strings. As a result, the
effect of the sscanf statement is to change typeof(strings) from
Array_Type to String_Type. Then in

() = fputs (strings[0], s_sig);

strings[0] refers to the zeroth character of the matched string. This
produces the type mismatch error because fputs expects a string
argument.

At some point I will add support for references to array and
structure elements but it is not very high on my list of priorities.
Until then, I will add code to flag &foo[n] as a parse error.

I hope this clarifies things a bit.
Thanks,
--John
Lars Stokholm
2005-01-14 10:00:41 UTC
Permalink
Post by John E. Davis
I hope this clarifies things a bit.
It did, thank you.

Loading...