Re: Tip 27: CONST qualifiers on pointer array arguments to TCL functions



* Don Porter <dgp@xxxxxxxxxxxxxx>
| Maybe you can find the reason in either TIP 27, or in
| http://wiki.tcl.tk/3669 .

I could not find anything related in TIP 27 itself. On google I found
some earlier discussion which involved char**, paragraph 3 in

http://groups.google.de/group/comp.lang.tcl/browse_thread/thread/a02c34b598c086e4/ba0fd2b3d54f1f10?lnk=st&q=const+argv+group:comp.lang.tcl&rnum=4&hl=de#ba0fd2b3d54f1f10

but I could not find that section in the TIP 27 itself.

However, one reference in http://wiki.tcl.tk/3669 makes me believe
that there is still a misunderstanding on the impact of adding
'const' to char** (or more generally, arrays of pointers) arguments.

http://sourceforge.net/mailarchive/message.php?msg_id=1235712 points
out that
<quote>
I can"t change those to take CONST84 char **s, since then they
wouldn"t be Tcl_CmdProcs anymore. It"s arguable that

typedef int Tcl_CmdProc(
ClientData clientData,
Tcl_Interp *interp,
int argc,
CONST84 char *argv[]);
^^^^^^^

would be the appropriate definition in the Core, since CmdProcs
aren"t supposed to modify the contents of argv[],
</quote>

Note that the above typedef is *NOT* appropriate to achieve a
non-modifiable argv, you need 'CONST84 char *CONST84 argv[]' for that.
And I really think that is what the prototype needs to be, since
exchanging a pointer in the argv-array in the Tcl_CmdProc (which is
possible if the argv itself is non-const) will likely break things
when the Tcl_CmdProc returns and the contents of the argv are for
example free()d.

| If this is really important to you, please file a feature request on
| it. Please include examples of what extension coding will be made
| easier or more elegant by the change.

This would be at sourceforge-TCL?

R'
.



Relevant Pages

  • Re: Weird pointer arithmetic on argv - How can it work??
    ... same as char **argv. ... argc -= optind; ... incrementing argv by the current value of optind ... and you're advancing it by optind pointers. ...
    (comp.lang.c)
  • Re: int main(int argc, char* argv[]) & int main(int argc, char** argv)
    ... When I use int main(int argc, char* argv[]) declaration, the argv usually ... If you are a newcomer to C++, don't feel bad, because arrays and pointers ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Pointers
    ... > One way to see the declaration syntax is that you ... > declare expression that evaluate to a certain type, char above. ... We hide pointers all the ... and there is no reason not to do the same things, ...
    (comp.lang.c)
  • Re: algorithm by eratosthenos
    ... The usual names for the parameters to main are argc and argv. ... I'm curious, how do you feel about int main(int ac, char **av)? ... any good reason not to use argc and argv. ...
    (comp.lang.c)
  • Re: starting into H&S
    ... pointers. ... why can't argv be NULL. ... Let's reason ... Remove del for email ...
    (comp.lang.c)