Tcl_WrongNumArgs(3tcl)
π Tcl_WrongNumArgs β the "bestie you gave me the wrong number of args" generator π
ok so this is a Tcl library procedure page, Tcl_WrongNumArgs(3tcl), and it's literally the thing that writes those iconic wrong # args: should be "..." messages you've definitely seen a million times. sit down, hydrate, let's go π«Ά
β¨ NAME β¨
Tcl_WrongNumArgs β generate standard error message for wrong number of arguments
β¨ SYNOPSIS β¨
#include <tcl.h>
Tcl_WrongNumArgs(interp, objc, objv, message)
β¨ ARGUMENTS β¨
Tcl_Interp interp(in) β the interpreter where the error gets reported, bestie. the error message gets stashed in its result value πTcl_Size objc(in) β how many leading arguments fromobjvwe're including in the error message.Tcl_Obj *const objv[](in) β the arguments to the command that had the wrong number of arguments. yeah. that command. the messy one πconst char *message(in) β extra error info to print after the leading arguments fromobjv. this usually gives the acceptable syntax of the command. and yes, this argument may beNULLβ¨
β¨ DESCRIPTION β¨
ok so Tcl_WrongNumArgs is a utility procedure that gets invoked by command procedures when they discover they've received the wrong number of arguments. it's giving error message factory, no cap. Tcl_WrongNumArgs generates a standard error message and stores it in the result value of interp. the message includes the objc initial elements of objv plus message.
for example, if objv consists of the values foo and bar, objc is 1, and message is fileName count then interp's result value will be set to the following string:
wrong # args: should be "foo fileName count"
and if objc is 2, the result will be set to the following string:
wrong # args: should be "foo bar fileName count"
objc is usually 1, but may be 2 or more for commands like string and the Tk widget commands, which use the first argument as a subcommand. main character behavior honestly π
π¦ the abbreviation glow-up (subcommand edition) π¦
some of the values in the objv array may be abbreviations for a subcommand. the command Tcl_GetIndexFromObj will convert the abbreviated string value into an indexObject. if an error occurs in the parsing of the subcommand we would like to use the full subcommand name rather than the abbreviation β like, give us the whole name, not the nickname π
if the Tcl_WrongNumArgs command finds any indexObjects in the objv array, it will use the full subcommand name in the error message instead of the abbreviated name that was originally passed in. using the above example, let us assume that bar is actually an abbreviation for barfly and the value is now an indexObject because it was passed to Tcl_GetIndexFromObj. in this case the error message would be:
wrong # args: should be "foo barfly fileName count"
see? full name, full slay. periodt β¨
β¨ REFERENCE COUNT MANAGEMENT β¨
listen up, this part matters π«Ά
the objv argument to Tcl_WrongNumArgs should be the exact arguments passed to the command or method implementation function that is calling Tcl_WrongNumArgs. as such, all values referenced in it should have reference counts greater than zero; this is usually a non-issue. lowkey chill, highkey important π
β¨ SEE ALSO β¨
Tcl_GetIndexFromObj(3tcl)β the one that makes theindexObjectmagic happen π
β¨ KEYWORDS β¨
command, error message, wrong number of arguments
and that's the whole vibe, bestie πΈ this page ships with Tcl 8.0, and it's Tcl_WrongNumArgs(3tcl) β so if your command procedure is about to throw hands over the arg count, you know exactly who to call πβ¨π¦ππ
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1994-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms