vcanim.gif (8357 bytes)SWU_tclArrayToCArray
Home ] Sales ] Products ] Services ] Support ] Downloads ]

 

 


SWU_tclArrayToCArray

SWU_listToCArray is a library procedure which allows users to convert Tcl array to a C array of type long, float, integer, or double. The input data is the Tcl array's name and the requested C numeric type (long, float, integer, or double).

It is important to note that although Tcl array indices can consist of any string value, C array indices are represented by consecutive integers beginning with 0. For example, consider a 3-element Tcl array with indices "Peter, Paul, Mary". Perhaps each element of the array consists of the individual's age. The resulting C array will simply use the (less informative) indices "0, 1, 2" to point to the element containing the age of each of the individuals.

package require SWU

SWU_tclArrayToCArray Tcl_array_name C_numeric_type
Tcl_array_name
specifies the Tcl array. See Tcl documentation regarding Tcl arrays.
C_numeric_type
See C documentation regarding the numeric types integer, float, and double.

Return Value

If the procedure succeeds then it returns the ID of a C array filled with values of the Tcl array's elements, otherwise an error message string is returned on the Tk console's command line.

Side Effects

None.

Examples

set varList [list 0 2.34 1 3.12 2 5.34 3 567.98 4 456.3]
0 2.34 1 3.12 2 5.34 3 567.98 4 456.3
array set varArray $varList
set arrayID [SWU_tclArrayToCArray varArray float]
FloatArray1
puts [access $arrayID 3]
567.98

This example sets varArray to an array of numbers, converts the varArray to a C array of type float, prints out the fourth element of the C array.

See Also

SWU_cArrayToList


Behaviors Overview ] Behavior Evaluate ] Behavior Edit ] Debugger ] Console ] Find ] SAA Library ] SW library ] SWC library ] SWN library index ] SWU library ] Attributes Index ] Scripting Examples ]

copyright Video-Collage Inc.