Can anyone explain what happend to an empty string ( "" ) when passed as parameter into a function.
I'm trying to do the TCL equivalnt for the C code :
void foo(const string & str ) {
if (str == "") {
cout << "Eurika";
}
}
What I see is that in the Tcl function the empty string is converted to \{\} # a 2 char string of pair of curely brackets
func foo {str} {
puts "string - $str"
puts "length - [string length $str]"
puts "char 0 - [string index $str 0 ]"
puts "char 1 - [string index $str 1 ]
if {$str == "" } { puts "Eurika" }
if {$str == "\{\}" } { puts "Why " }
}
> foo ""
string - {}
length - 2
char 0 - {
char 1 - {
Why
# Running foo {} or foo \{\} gives the same
???
I'm trying to do the TCL equivalnt for the C code :
void foo(const string & str ) {
if (str == "") {
cout << "Eurika";
}
}
What I see is that in the Tcl function the empty string is converted to \{\} # a 2 char string of pair of curely brackets
func foo {str} {
puts "string - $str"
puts "length - [string length $str]"
puts "char 0 - [string index $str 0 ]"
puts "char 1 - [string index $str 1 ]
if {$str == "" } { puts "Eurika" }
if {$str == "\{\}" } { puts "Why " }
}
> foo ""
string - {}
length - 2
char 0 - {
char 1 - {
Why
# Running foo {} or foo \{\} gives the same
???