| Ralf Fassel 2006-05-25, 8:14 am |
| * "maura.monville@gmail.com" <maura.monville@gmail.com>
Whenever you write TCL code such as
if {[some_c_routine]} { ... }
you implicitly assume that the routine returns TCL_OK, and the
interpreter result of calling the C routine is some boolean value.
If your C-code returns TCL_ERROR, the 'if' will not run at all, but
TCL will abort execution the proc containing that code.
So if you need the C code simply to determine yes/no, you would do it
like this:
static int
check_hist_aint_option_cb( ... ) {
// default result is false
int result = 0;
// check our data structures
if ( hg.active_ > 0 ) {
for (int i = 0; i < Length_of_AINT_histo_ID; ++i) {
if (hg.hid_ == AINT_histo_ID[i]) {
// found something, result is true
result = 1;
break;
}
}
}
// set the result of calling this routine from TCL
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(result));
// tell TCL we have performed our task succesfully
return TCL_OK;
}
| My C routine checks the validity of a selected option for the
| currently displayed histogram. Therefore it returns a Boolean value
| that, according to the C <-> Tcl communucation protocol, I have
| encoded as TCL_ERROR (= FALSE) and TCL_OK (TRUE).
Returning TCL_ERROR or TCL_OK are meant as a means for TCL to find out
whether or not the C code has performed it's task successfully.
Returning TCL_ERROR or TCL_OK is *not* the result you will see in the
TCL code.
R'
|