Tcl_SetStringObj question
- From: icanbob@xxxxxxxxx
- Date: Mon, 28 Jul 2008 09:08:05 -0700 (PDT)
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
.
- Follow-Ups:
- Re: Tcl_SetStringObj question
- From: Don Porter
- Re: Tcl_SetStringObj question
- From: fredericbonnet
- Re: Tcl_SetStringObj question
- Prev by Date: [XOTcl] Referencing values in an array
- Next by Date: Re: Tcl_SetStringObj question
- Previous by thread: [XOTcl] Referencing values in an array
- Next by thread: Re: Tcl_SetStringObj question
- Index(es):