implementation of char()
Thorsten Meyer
thorsten.meyier at gmx.de
Fri Jan 2 03:11:37 CST 2009
Thorsten Meyer wrote:
> I have a question regarding the implementation of the char() function:
>
> in the source code (in src/strfns.cc) for char() the one argument case is treated specially:
> - for one argument, the convert_to_str method is used directly with three arguments, the third
> being args(0).is_dq_string () ? '"' : '\''
> - for more than one argument, the all_strings method is used for each argument individually, and
> within all_strings (defined in ovbase.cc) convert_to_str is used with two arguments.
>
> What is the purpose of this special treatment of the on argument case?
Now I found a difference between the one-argument-case and the more-than-one-argument case:
octave:7> clear
octave:8> a(1,1,1,1)=100;
octave:9> a(3,3,3,3)=101;
octave:10> b=char(a);
octave:11> b=char(a, 102);
error: invalid conversion of charNDArray to string_vector
error: char: unable to convert some args to strings
octave:11>
So convert_to_str can deal with more than 2 dimensions, while all_strings cannot. But why, when
all_strings uses convert_to_str to do the actual conversion? I suspect, that the answer lies in the
way both functions are overloaded for different kind of data. But I am hopelessly lost in the source
code. Can somebody give me a hint where to look?
thanks
Thorsten
More information about the Help-octave
mailing list