本文介绍了在处理64位机的文件,但在32位机发展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要去阅读在64位Windows计算机C语言使用Mexfunction在MATLAB TDMS文件,但我将开发32位Windows计算机的应用程序。我知道在有32位机,并与变量的大小为64位之间的差。我用了很多的fread的(..的sizeof(型)..)。它是将是一个问题,当它在64位机上运行?如果是这样,我怎么可以把它移植到64位mahince?

i am going to read a TDMS file in matlab using Mexfunction in C language in a 64 bit windows machine, but i will develop the app in 32 bit windows machine. i know in there is a difference between 32 bit machine and 64 bits with the size of variables. i used a lot of fread(.. sizeof(type)..). is it going to be a problem when it is running in 64 bit machine? if so, how can i make it portable to 64 bits mahince?

感谢

推荐答案

更​​普遍的问题是,你必须知道哪些变量的大小是该写的文件,而不是机器,是阅读他们的机器上。换句话说,你可以说的sizeof(int)和让说,8一些疯狂的64位系统上,但如果文件被保存在一个正常的32位计算机上,的sizeof(int)的可能是4(或甚至2,根据ANSI C,我认为)。 sizeof运算指令会告诉你一个int的大小,或什么的,在本地计算机上在编译的时候。但它不能告诉你有关保存该文件的计算机的任何信息。

The more general problem is that you will have to know what the size of the variables were on the machine that WROTE the file, not the machine that is reading them. In other words, you can say sizeof(int) and get say 8 on some crazy 64 bit system, but if the file was saved on a normal 32 bit machine, sizeof(int) may be 4 (or even 2, according to ansi c, I think). The sizeof command will tell you the size of an int, or whatever, on your local machine at the time of compile. But it can't tell you anything about the machine that saved the file.

您最好的办法是看是否TDMS标准(我不熟悉)定义变量的大小。如果是这样,你应该使用这些,而不是sizeof的。

Your best bet is to see if the TDMS standard (I'm not familiar with it) defines variable sizes. If so, you should use those, rather than sizeof.

一个可怜的第二种方法是在文件的开头有一个测试序列,并动态调整大小可变,直到你可以正确读取测试序列。

A poor second alternative is to have a test sequence at the beginning of the file and dynamically adjust your variable sizes until you can read the test sequence correctly.

这篇关于在处理64位机的文件,但在32位机发展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 19:24