Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tcl_ExprLong documentation omission

Open31fedb885e801f4cc41c7b1f4438e27ce4a3667fCreated 2 years agoUpdated 2 years ago
Descriptionplain2025-03-25 00:09:34
The man page documenting the Tcl functions Tcl_ExprLong(), Tcl_ExprDouble(), Tcl_ExprBoolean() and Tcl_ExprString() omits to mention that these four functions returns TCL_OK and write a zero in the passed in variable if an empty string is provided (*expr == '\0').

This is relevant since evaluating an empty string in Tcl results in a different result.

$ tclsh9.1 
% expr {}
empty expression
in expression ""
jan.nijtmanswiki2025-03-26 19:54:44

In the code, I see this:

    if (*exprstring == '\0') {
        /*
         * Legacy compatibility - return 0 for the zero-length string.
         */

*ptr = 0; } else {

This tells me that this behavior was not intended, but kept for compatibility with old versions of Tcl.

Wouldn't it be better to fix this behavior, generating an error-message in this case?

apnadkarnimarkdown2025-03-27 02:51:59

While I too would prefer fixing this as opposed to changing the documentation, I fear that opportunity might have passed with 9.0 release depending on whether one believes manpages are authoritative or the actual implementation.

Also, Tcl_ExprLongObj etc. may also have the same issue though I have not checked the actual behavior in those cases.

jan.nijtmanswiki2025-03-27 07:03:16

Or ... just deprecate those functions in 9.1 and remove them in 9.2. Or ... deprecate those in 9.0 and remove them in 9.1 ....

I only found 2 extensions still using any of those: Blt and Tix.

> Also, Tcl_ExprLongObj etc. may also have the same issue though I have not checked the actual behavior in those cases.

No, the *Obj() functions are OK, they - correctly - output an error-message in this case.

Log in (anonymous is fine) to add a comment.