cproc strrev s {
/* Revert a string */
char *cp = s+strlen(s);
while(cp > s) putchar(*--cp);
}
strrev "A man, a plan, a canal: Panama" ;#=> amanaP :lanac a ,nalp a
,nam A
which are spliced into a C source, compiled, executed - took 'bout 2
seconds on my P200/W95 box; or a proc to make a new wish/tclsh with
static C extensions:
cxtend -Tk 1 -name mywish -cc gcc -ccflags {-s -Wall} -cmd {
strrev {char* s} {
char *cp0, *cp1, t;
for(cp0=s, cp1=s+strlen(s)-1; cp1>cp0; cp0++, cp1--) {
t=*cp0; *cp0=*cp1; *cp1=t; /* This is C */
}
} {char* s}
} ;# and back in Tcl - note the result parameter must also be declared
makes C source for mywish.exe, that, besides all of standard Tcl/Tk,
contains the C command 'strrev' (compiles & links in 3 seconds, size of
stripped executable is just 3.5KB!). This is fresh (I only started
yesterday evening), but the generated code raises no warnings with gcc
and works as expected. Is Tcl cool!
--
Schoene Gruesse/best regards, Richard Suchenwirth - +49-7531-86 2703
RC DT2, Siemens Electrocom, Buecklestr. 1-5, D-78467 Konstanz,Germany
-------------- http://purl.org/thecliff/tcl/wiki//Richard*Suchenwirth
Bug: Divided by zero! Fix: Multiply by zero. (Babbage, JUST-IN-CASE)