在64位机器上强制32位长? [英] forcing 32-bit long on 64-bit machine?

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

问题描述

嗨伙计们,


我有一台64位机器,在这台机器上我想运行

一个旧程序,这个程序是为了假设多头是32位。

我已经发现这台机器上的gcc自动

使长64位。


而不是通过代码并将所有多数转换为整数(gcc使得32位),是否有一个开关来使gcc

将long定义为32位? br />

谢谢。

解决方案

CoffeeGood写道:

I有一台64位的机器,在这台机器上,我想运行一个旧的程序,这个程序是为了假设long是32位的。
我已经在这台机器上自动发现了gcc
而不是通过代码并将所有长的转换为int(gcc使得32位),是否有转换来制作gcc
将long定义为32位?



在gnu.gcc上询问gcc人员;这是一个特定于编译器的问题。


如果您决定转换多头而不是更改平台

(这是你正在尝试的做),#include< stdint.h>并转换

将它们转换为(u)int32_t。这是一个(无符号)整数类型,如果它存在,则具有32位

比重写代码使它在第一个

的地方不使用这样的假设。


S. br />


CoffeeGood说:

嗨伙计们,

我有一台64位机器,就此而言机器我想运行
一个旧程序,编写假设long是32位。


错误的代码。

我发现这台机器上的gcc会自动生成长64位。


好​​的编译器。更好的编译器,因为它暴露了错误的代码!

而不是通过代码并将所有长的转换为int(gcc使得32位),是否有转换来制作gcc
将long定义为32位?




您是否考虑过在gcc新闻组中提问? gnu.gcc.help可能值得一个

go。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)


CoffeeGood写了

(文章

< 11 ********************* @ g14g2000cwa.googlegroups.com>):
< blockquote class =post_quotes>嗨伙计们,

我有一台64位机器,在这台机器上我想运行一个旧程序,编写假设long是32位。


好​​的。这个假设是否意味着如果它们更大,它会破裂吗?有时像这样的应用程序对数据大小的最低要求是

,但如果它更大,它将起作用。你确定

这不是这种情况吗?

我发现这台机器上的gcc会自动生成长64位。


您通常可以告诉编译器生成32位二进制文​​件,即使在64位内核上运行也是如此(如我所怀疑的那样) )

AMD /英特尔'x86-64'系列的一部分。请参阅

gcc的手册页,或者更合适的是,在gcc

特定新闻组之一中进行此操作。

而不是去通过代码并将所有多数转换为int(gcc使得32位),是否有一个开关使gcc
将long定义为32位?




我想修改代码以便它没有任何不必要的

关于数据类型大小的假设从未作为选项出现过吗?

-

兰迪霍华德(2个人正在删除FOOBAR)

准确观察的力量被那些没有得到它的人称为玩世不恭。 - George Bernard Shaw


Hi folks,

I have a 64-bit machine and on this machine I want to run
an old program that was written to assume that longs are 32 bits.
I''ve discovered however that gcc on this machine automatically
makes longs 64 bits.

Rather than go through the code and convert all longs
to ints (which gcc makes 32 bits), is there a switch to make gcc
define longs as 32 bits?

Thanks.

解决方案

CoffeeGood wrote:

I have a 64-bit machine and on this machine I want to run
an old program that was written to assume that longs are 32 bits.
I''ve discovered however that gcc on this machine automatically
makes longs 64 bits.

Rather than go through the code and convert all longs
to ints (which gcc makes 32 bits), is there a switch to make gcc
define longs as 32 bits?


Ask the gcc folks at gnu.gcc; this is a compiler-specific question.

If you do decide to convert the longs rather than change the platform
(which is what you''re trying to do), #include <stdint.h> and convert
them to (u)int32_t. That''s an (unsigned) integer type with exactly 32
bits, if it exists, and solves the problem once and for all. Well, other
than rewriting the code to make it not use such assumptions in the first
place.

S.


CoffeeGood said:

Hi folks,

I have a 64-bit machine and on this machine I want to run
an old program that was written to assume that longs are 32 bits.
Bad code.
I''ve discovered however that gcc on this machine automatically
makes longs 64 bits.
Good compiler. Better compiler, because it exposes bad code!
Rather than go through the code and convert all longs
to ints (which gcc makes 32 bits), is there a switch to make gcc
define longs as 32 bits?



Have you considered asking in a gcc newsgroup? gnu.gcc.help might be worth a
go.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


CoffeeGood wrote
(in article
<11*********************@g14g2000cwa.googlegroups. com>):

Hi folks,

I have a 64-bit machine and on this machine I want to run
an old program that was written to assume that longs are 32 bits.
Okay. Does that assumption imply that it will break if they are
bigger? Sometimes apps like this have a minimum requirement for
data size, but if it''s bigger it will work. Have you made sure
that isn''t the case here?
I''ve discovered however that gcc on this machine automatically
makes longs 64 bits.
you can usually tell the compiler to generate a 32-bit binary,
even when running on a 64-bit kernel if it is (as I suspect)
part of the AMD/Intel ''x86-64'' family. See the man page for
gcc, or even more appropriately, take this up in one of the gcc
specific newsgroups.
Rather than go through the code and convert all longs
to ints (which gcc makes 32 bits), is there a switch to make gcc
define longs as 32 bits?



I suppose fixing the code so that it didn''t make unwarranted
assumptions about data type sizes never came up as an option?
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw


这篇关于在64位机器上强制32位长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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