如何定义一个8位整数 [英] how to define an 8 bit integer

查看:336
本文介绍了如何定义一个8位整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过许多遗留代码使用uint8_t或uint16_t来覆盖整数'长度的

默认编译器设置。


我正在使用Linux上的gcc和sizeof(int)给了我4.我希望

能够定义8位,16位或32位整数。


我尝试过使用uint8_t但是gcc不喜欢它。我是否需要修改

任何设置或声明typdefes。


请指导我。非常感谢您的回答。


谢谢,

I have seen many legacy code use uint8_t or uint16_t to override the
default compiler setting of an integer''s length.

I am using gcc on Linux and a sizeof(int) gives me 4. I want the
ability to define an 8, 16 or 32 bit integer.

I tried using uint8_t but the gcc doesn''t like it. Do I need to modify
any setting or declare typdefes.

Please guide me. Your answer is greatly appreciated.

Thanks,

推荐答案

DanielJohnson写道:
DanielJohnson wrote:

我见过许多遗留代码使用uint8_t或uint16_t来覆盖整数'长度的

默认编译器设置。


我在Linux上使用gcc而sizeof(int)给了我4.我希望

能够定义8位,16位或32位整数。

我尝试使用uint8_t,但gcc不喜欢它。我是否需要修改

任何设置或声明typdefes。
I have seen many legacy code use uint8_t or uint16_t to override the
default compiler setting of an integer''s length.

I am using gcc on Linux and a sizeof(int) gives me 4. I want the
ability to define an 8, 16 or 32 bit integer.

I tried using uint8_t but the gcc doesn''t like it. Do I need to modify
any setting or declare typdefes.



默认情况下,gcc为不符合要求的C版本编译

有点像C90,有很多类似的功能对于添加到C99的功能,但并不总是与b $ b相同。 uint8_t在C99中添加。

使用-std = c99打开对C99的支持。添加-pedantic来一点点

更接近完全符合C99。


如果因任何原因你不能使用C99,请使用以下:


typedef unsigned char uint8;


如果编译器支持任何无符号的8位整数类型,则unsigned char

将是这样一种类型。如果编译器没有8位整数类型,那么
''unsigned char''将是该

编译器的最佳近似值。

By default, gcc compiles for for a non-conforming version of C that is
sort of like C90 with many features that are similar, but not always
identical, to features that were added to C99. uint8_t was added in C99.
Use -std=c99 to turn on support for C99. Add -pedantic to come a little
closer to being fully conforming to C99.

If for any reason you can''t use C99, use the following:

typedef unsigned char uint8;

If a compiler supports any unsigned 8-bit integer type, unsigned char
will be such a type. If the compiler has no 8-bit integer type,
''unsigned char'' is going to be the best approximation possible for that
compiler.


2008年10月25日19:56,DanielJohnson写道:
On 25 Oct 2008 at 19:56, DanielJohnson wrote:

我在Linux上使用gcc和sizeof(int)给我4.我希望

能够定义8位,16位或32位整数。


我尝试使用uint8_t但是gcc没有喜欢它。我是否需要修改

任何设置或声明typdefes。
I am using gcc on Linux and a sizeof(int) gives me 4. I want the
ability to define an 8, 16 or 32 bit integer.

I tried using uint8_t but the gcc doesn''t like it. Do I need to modify
any setting or declare typdefes.



所有这些神秘的可移植性问题都被GNU autotools等创建者认真考虑,解决了,并且很好地调试了这些问题,所以

为什么重新发明轮子?


查看autoconf宏AC_TYPE_INT8_T,AC_TYPE_INT16_T,

AC_TYPE_INT32_T和AC_TYPE_INT64_T。

All these arcane portability issues have been thought of, solved, and
painfully debugged by the creators of things like the GNU autotools, so
why reinvent the wheel?

Look at the autoconf macros AC_TYPE_INT8_T, AC_TYPE_INT16_T,
AC_TYPE_INT32_T and AC_TYPE_INT64_T.




" DanielJohnson" < di ******** @ gmail.com在消息中写了

"DanielJohnson" <di********@gmail.comwrote in message

我在Linux上使用gcc而sizeof(int)给了我4.我希望

能够定义8位,16位或32位整数。
I am using gcc on Linux and a sizeof(int) gives me 4. I want the
ability to define an 8, 16 or 32 bit integer.



为什么?


-

免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm

Why?

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


这篇关于如何定义一个8位整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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