Overview
| Artifact ID: | 5fd11238434a4f01a3d56bf0431fa4a0aeb741bd |
|---|---|
| Ticket: | 1917650fffffffffffffffffffffffffffffffff |
| Date: | 2008-03-18 09:25:40 |
| User: | hkoba |
| Artifact Attached: | d047daf9bfead93e23cbcf901dcb3ef40ccb73a0 |
| Filename: | tcl-convertto-double.c |
| Description: |
Content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54/* * gcc -Wall -I/usr/local/include -g tcl-convertto-double.c \ -L/usr/local/lib -ltcl8.5 -Wl,-rpath,/usr/local/lib */ #include <tcl.h> #include <string.h> #include <stdio.h> #include <assert.h> char* default_test[] = { "100", "200", "300" }; int main(int argc, char** argv) { Tcl_Interp* interp = Tcl_CreateInterp(); Tcl_Obj** values; Tcl_ObjType* doubleType = Tcl_GetObjType("double"); int rc, i, testc; char** tests = 0; if (--argc > 0) { tests = ++argv; testc = argc; } else { tests = default_test; testc = sizeof(default_test) / sizeof(char*); } if ((values = (Tcl_Obj**) Tcl_Alloc(sizeof(Tcl_Obj*) * testc)) == NULL) { return 1; } for (i = 0; *tests; tests++, i++) { values[i] = Tcl_NewStringObj(*tests, strlen(*tests)); } for (i = 0; i < testc; i++) { if ((rc = Tcl_ConvertToType(interp, values[i], doubleType)) != TCL_OK) { fprintf(stderr, "conversion error for %s\n", values[i]->bytes); return 1; } /* This fails under Tcl8.5 */ assert(values[i]->typePtr == doubleType); printf("doubleValue = %f type=%s bytes=%s\n" , values[i]->internalRep.doubleValue , values[i]->typePtr->name , values[i]->bytes); } return 0; }