数据类型 [英] data types

查看:74
本文介绍了数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




过去几个月我一直在这个项目上工作,我的余额很多,现在我开始工作了在我的petzold书中,Windows界面和

,我已经认识到,对于PC来说,int可以为b-b $ 32 $ b。哦,我可以开始自己没有在

中检查好,但我使用的编译器说明int是

16位。它可能已经过时了。


无论如何,现在我需要回过头来仔细查看我的代码,

我的问题是:有没有一种声明变量的方法在C中说一个16位

无符号整数?或者宣称它是短的。唯一的说明者

可能有用吗?


提前致谢

Hi,

I''ve been working on this project for the past few months in my spare
time, and now I started working on the windows interface and going
over my petzold book, I''ve come to the realization that an int could
be 32-bit for PCs. Oh, I could kick myself for not checking good in
the beginning, but the manual for the compiler I am using says int is
16-bit. It may be out of date.

Anyway, now that I need to go back over and look closely at my code,
my question is: is there a way to declare a variable say a 16 bit
unsigned integer in C? Or is declaring it "short" the only specifier
that may work?

Thanks in advance

推荐答案

ko********@yahoo.com 写道:
ko********@yahoo.com wrote:

> ...对于PC来说,int可能是32位。
...但是我使用的编译器手册说int是
16位。

无论如何,现在我需要回过头来仔细查看我的代码,
我的问题是:有没有办法声明一个变量说C中的16位无符号整数?或者宣称它是短的。可行的唯一说明者

>... an int could
be 32-bit for PCs.
...but the manual for the compiler I am using says int is
16-bit.

Anyway, now that I need to go back over and look closely at my code,
my question is: is there a way to declare a variable say a 16 bit
unsigned integer in C? Or is declaring it "short" the only specifier
that may work?



对于非C99编译器,常见的,不可移植的方式是:


typedef [无论何种类型你的平台是16位] int16;

typedef [平台中32位的任何类型] int32;


等等。然后使用int16 / 32 / etc。而不是你的代码中的普通int。

For non-C99 compilers, the common, non-portable way of doing it is:

typedef [whatever type is 16 bits in your platform] int16;
typedef [whatever type is 32 bits in your platform] int32;

and so on. Then use int16/32/etc. instead of plain int in your code.


>提前感谢
>Thanks in advance



Roberto Waltman

[请回复小组,

返回地址无效]

Roberto Waltman

[ Please reply to the group,
return address is invalid ]


Roberto Waltman写道:
Roberto Waltman wrote:
ko********@yahoo.com 已写:

ko********@yahoo.com wrote:


>> ...对于PC来说,int可能是32位。
...但是我正在使用的编译器手册说是16位的


无论如何,现在我需要回过头来仔细查看我的代码,
我的问题是:有没有办法在C中声明一个16位无符号整数的变量?或者宣称它是短的。可行的唯一说明者

>>... an int could
be 32-bit for PCs.
...but the manual for the compiler I am using says int is
16-bit.

Anyway, now that I need to go back over and look closely at my code,
my question is: is there a way to declare a variable say a 16 bit
unsigned integer in C? Or is declaring it "short" the only specifier
that may work?



对于非C99编译器,常见的,不可移植的方式是:


typedef [无论何种类型你的平台是16位] int16;

typedef [平台中32位的任何类型] int32;


等等。然后使用int16 / 32 / etc。而不是代码中的plain int。


For non-C99 compilers, the common, non-portable way of doing it is:

typedef [whatever type is 16 bits in your platform] int16;
typedef [whatever type is 32 bits in your platform] int32;

and so on. Then use int16/32/etc. instead of plain int in your code.



int16_t会更好,以匹配< stdint.h>中的类型。


-

Ian Collins。

int16_t would be better, to match the types in <stdint.h>.

--
Ian Collins.


ko ******** @ yahoo.com 写道:




我过去几个月一直在这个项目上工作,我花了很多时间,现在我开始在windows界面上工作了。

over my petzold的书,我已经意识到一个int可以为个人电脑提供32位的b。
Hi,

I''ve been working on this project for the past few months in my spare
time, and now I started working on the windows interface and going
over my petzold book, I''ve come to the realization that an int could
be 32-bit for PCs.



对于特定的C实现,int是(sizeof(int)* CHAR_BIT)

位。对于现代PC来说,它通常是32或64.

For a particular C implementation an int is (sizeof(int) * CHAR_BIT)
bits. For modern PCs it''s often 32 or 64.


哦,我可以踢自己没有检查好

一开始,但我正在使用的编译器说明int是

16位。它可能已经过时了。
Oh, I could kick myself for not checking good in
the beginning, but the manual for the compiler I am using says int is
16-bit. It may be out of date.



可能是。

Could be.


无论如何,现在我需要回过头去仔细看看我的代码,

我的问题是:有没有办法在C中声明一个变量说16位

无符号整数?或者宣称它是短的。可能有效的唯一说明者


Anyway, now that I need to go back over and look closely at my code,
my question is: is there a way to declare a variable say a 16 bit
unsigned integer in C? Or is declaring it "short" the only specifier
that may work?



为什么你需要一个N位的对象?


如果你的编译器不是C99的那个,那么似乎是,那么你将需要自己定义一个16位类型。这并不困难。对于

示例,如果在您的实现中,int发生的是16位,则

unsigned int是您想要的类型。您可以创建一个别名:


typedef unsigned int int16;


但除非您有特定要求,否则我建议安装

当前编译系统。 Windows有很多选择,不过我建议使用gcc版本(Cygwin或MinGW)或Visual Studio

Express。

如果您的实现确实支持C99,(并且您不介意部分

支持),请查看stdint.h中的类型。 uint16_t或

uint_least16_t可能满足您的需求。

Why do you need an object of exactly N bits?

If your compiler is not a C99 one, as it appears to be, then you''ll
have to define a 16-bit type yourself. It''s not difficult. For
example, if, under your implementation, int happens be 16 bits then
unsigned int is the type you want. You can create an alias like:

typedef unsigned int int16;

But unless you have a specific requirement, I suggest installing a
current compiler system. You have many choices for Windows, though I
recommend either a version of gcc, (Cygwin or MinGW), or Visual Studio
Express.

If your implementation does support C99, (and you don''t mind partial
support), have a look at the types in stdint.h. uint16_t or
uint_least16_t may meet your needs.


这篇关于数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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