Tcl_SetStringObj question



The SIMPL project (http://www.icanprogram.com/simpl) has been
maintaining a Tcl/Tk shared library for a number of years now.

Recently I was using this shared library and found a "strange" issue.

The shared library uses the following sequence to return an error
condition:

========= begin C snip ===============
rc=name_attach(name, NULL);

if (rc != -1)
sprintf(myname,"%s.%d", name, getpid());
else
sprintf(myname,"NULL");

resultPtr = Tcl_GetObjResult(interp);
Tcl_SetStringObj(resultPtr, myname, sizeof(myname));

return TCL_OK;
========= end C snip ================

However if the Tcl program uses the following sequence:

========= begin Tcl snip ==============
#!/usr/bin/tclsh

lappend auto_path $env(SIMPL_HOME)/lib
package require Fctclx

set myslot [name_attach ""]
puts stdout [format "myslot = <%s>" $myslot]
puts stdout [format "compare=%d" [string compare $myslot "NULL"]]
if { [string compare $myslot "NULL"] == 0 } {
puts stdout [format "%s: cannot attach name" $myName]
} else {
puts stdout [format "passes"]
}
======== end Tcl snip ================

the output comes out

myslot =<NULL>
compare=1
passes

In other words even though the Tcl_SetStringObj sets a string equal to
"NULL" there doesn't appear to be any obvious way to compare this in a
Tcl if statement.

Thanks in advance for any help offered.

bob
.