slang-users mailing list

[2007 Date Index] [2007 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] Why __add_string() is not used for strcat()?


=?UTF-8?Q?J=C3=B6rg?= Sommer <joerg@xxxxxxxxxxxx> wrote:
>why is the function registered with __add_string() not used for strlen(),
>strcat() and thelike? I thought this functions is used everywhere a
>string is needed.

No.  It simply defines a string representation of a user-defined type.
It does not automatically convert the object to a string when one is
needed.

To understand the rationale behind this decision, consider:

   z = 1+2i;
   vmessage ("z=%S", z);

This results in the message

   z=(1 + 2i)

since "%S" is a format-specifier for the string representation of the
object.  If the string representation were to be used in all contexts,
then strcat (z,z) would produce "(1 + 2i)(1 + 2i)" instead of a
type-mismatch error.  So if a function calls for a string, then it
must be passed a string and not some other object, e.g., use string(z)
to get the string representation.

The C interface permits application-defined types to be transparantly
converted to strings, but I have not added a "typecast" method to the
slang layer yet.  Is that what you are looking for?

Thanks,
--John





[2007 date index] [2007 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]