Posted to tcl by evilotto at Thu Aug 22 20:12:54 GMT 2013view pretty

package require critcl

critcl::cproc mkbad {Tcl_Interp* i char* st} void {
    Tcl_DString d;
    char *end=st+strlen(st);
    Tcl_DStringInit(&d);
    do {
	char *n=Tcl_UtfNext(st);
	Tcl_DStringAppend(&d, st, n-st);
	st=n;
    } while (st<end);
    Tcl_DStringResult(i,&d);
    Tcl_DStringFree(&d);
}

set a [mkbad ""]
set b "\0"

puts [expr {$a ne $b}]
puts [expr {[binary encode hex $a] eq [binary encode hex $b]}]

puts [string length $a]
puts [string length $b]

puts [tcl::unsupported::representation $a]
puts [tcl::unsupported::representation $b]