简体   繁体   中英

How to read float from binary file using Tcl_ReadChars?

The preferred method for reading from a channel using the Tcl API is Tcl_ReadChars() . When reading from a binary channel, the data will be stored as a byte array until referenced, at which point conversions will be done.

I then have a set of functions for retrieving data from the object: Tcl_Get{String,Double,Int}FromObj() . However, if I read in a float, it seems that none of these will do the right thing to extract the value I intended.

At this point, I am trying to reason from the documentation. It may be the case that Tcl_GetDoubleFromObj() will be flexible enough to handle this case... but that doesn't seem to be the case based on the documentation.

Using the Tcl C API, how should I read a float from a binary file?

I can't swear this is the source of the implementation of your Tcl_GetDoubleFromOjb() , but it looks like it might be a version of it: http://tclsrc.tyabo.com/tclObj_8c-source.html

It doesn't look like it's doing a straight conversion of a raw double. It looks like it's pulling a double from a TCL created object, not a stream of raw bytes.

Maybe you want to look into binary scan as a way of pulling the floats/doubles out of your binary stream?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM