在 64 位机器上处理文件但在 32 位机器上开发 [英] processing files in 64 bit machine but developing in 32 bit machine

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

问题描述

我将在 64 位 Windows 机器上使用 C 语言中的 Mexfunction 在 matlab 中读取 TDMS 文件,但我将在 32 位 Windows 机器上开发该应用程序.我知道 32 位机器和 64 位机器之间存在变量大小的区别.我使用了很多 fread(.. sizeof(type)..).在64位机器上运行会不会有问题?如果是这样,我怎样才能使它可移植到 64 位机器?

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) 并在一些疯狂的 64 位系统上说 8,但如果文件保存在普通的 32 位机器上,则 sizeof(int) 可能是 4(甚至 2,根据 ansic,我认为).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 位机器上开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆