Skip to content
Tcl Source Code View Ticket
Login

View Ticket

New API function: Tcl_PrintfResult

Closed / Accepted1184069fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 20 years ago
Descriptionplain2005-04-15 23:14:26
It would be really nice (especially for error
generation) if we could have a function that let us
write strings into the interpreter result as a
replacement for the old trick of:
  sprintf(interp->result, "pattern")

Notes on implementation: Need to use vsnprintf
internally to work out the required size of buffer
before allocating it and feeding it through vsprintf
(the trick done in glib is not portable enough without
this).
jenglishplain2005-05-04 04:54:49
Logged In: YES 
user_id=68433

vsnprintf() is new in C99, it's not part of C89.

Since C99 still isn't widely supported (and the core hasn't
even been fully update to C89 yet), we should tread
carefully when approaching C9X-isms.
dkfplain2005-05-04 06:07:11
Logged In: YES 
user_id=79902

Yuck. The problem is that only (v)snprintf() returns the
number of characters that would have been written instead of
the number of characters actually written. Without it,
sizing the buffer for vsprintf() is tricky/impossible.
dgpplain2005-11-01 23:54:39
Logged In: YES 
user_id=80530


See TclObjPrintf() and
TclFormatToErrorInfo()
on the HEAD.
msofer Ticket [1184069fff]: 1 change [History diff]2005-11-26 17:41:04
dkf Ticket [1184069fff]: 1 change [History diff]2006-08-09 17:24:52
dgpplain2006-08-09 20:53:27
Logged In: YES 
user_id=80530


See TIP 270.  In terms of
the routines proposed there:

  objPtr = Tcl_NewObj();
  Tcl_ObjPrintf(NULL, objPtr, format, arg, arg);
  Tcl_SetObjResult(interp, objPtr);
dgpplain2006-11-03 02:40:55
Logged In: YES 
user_id=80530


After some revisions to
TIP 270, this request is
satisfied in terms of the
proposed routines by:

  Tcl_SetObjResult(interp,
      Tcl_ObjPrintf(format, arg, arg));
dgpplain2006-11-14 23:33:49
Logged In: YES 
user_id=80530

TIP 270 accepted for 8.5a6.
Log in (anonymous is fine) to add a comment.