unsigned

Why C compiler cannot do signed/unsigned comparisons in an intuitive way [closed]

自作多情 提交于 2020-01-14 10:26:08
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . By "intuitive" I mean given int a = -1; unsigned int b = 3; expression (a < b) should evaluate to 1. There is a number of questions on

Linux中断管理机制

淺唱寂寞╮ 提交于 2020-01-13 17:21:04
转自 https://www.cnblogs.com/arnoldlu/p/8659981.html 新的linux kernel 及 arm不支持 中断嵌套。 关键词:GIC、IAR、EOI、SGI/PPI/SPI、中断映射、中断异常向量、中断上下文、内核中断线程、中断注册。 由于篇幅较大,简单梳理一下内容。 本章主要可以分为三大部分: 讲解硬件背景的 1. ARM中断控制器 。 系统初始化的静态过程:GIC初始化和各中断的中断号映射 2. 硬件中断号和Linux中断号的映射 ;每个中断的注册 5. 注册中断 。 一个中断从产生到执行完毕的动态过程:ARM底层通用部分如何处理 3. ARM底层中断处理 ;GIC部分的处理流程以及上层通用处理部分 4. 高层中断处理 。 这里的高层处理,没有包括下半部。下半部在 Linux中断管理 (2)软中断和tasklet 和 Linux中断管理 (3)workqueue工作队列 中进行介绍。 1. ARM中断控制器 1.1 ARM支持中断类型 ARM GIC-v2支持三种类型的中断: SGI:软件触发中断(Software Generated Interrupt),通常用于多核间通讯,最多支持16个SGI中断,硬件中断号从ID0~ID15。SGI通常在Linux内核中被用作IPI中断(inter-processor interrupts)

Unsigned negative primitives?

房东的猫 提交于 2020-01-13 09:14:08
问题 In C++ we can make primitives unsigned . But they are always positive. Is there also a way to make unsigned negative variables? I know the word unsigned means "without sign", so also not a minus (-) sign. But I think C++ must provide it. 回答1: No. unsigned can only contain nonnegative numbers. If you need a type that only represent negative numbers, you need to write a class yourself, or just interpret the value as negative in your program. (But why do you need such a type?) 回答2: unsigned

warning C4146 minus operator on unsigned type

我的梦境 提交于 2020-01-13 04:29:50
问题 I have this code from a library I want to use. On compiling, I get the following warning: warning C4146: unary minus operator applied to unsigned type, result still unsigned inline int lastbit (uint32_t v) { int r; static const int MultiplyDeBruijnBitPosition[32] = { 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 }; r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27]; return r; } How can I fix it

C语言类型强制转换

两盒软妹~` 提交于 2020-01-13 04:24:28
C语言类型强制转换 强制类型转换 是通过类型转换运算来实现的。其一般形式为: (类型说明符) ( 表达式 ) 其功能是把表达式的运算结果 强制转换 成类型说明符所表示的类型。 目录 1 基本介绍 2 注意事项 1 基本介绍 编辑 强制类型转换 是通过类型转换运算来实现的。其一般形式为:(类型说明符)( 表达式 )其功能是把表达式的运算结果 强制转换 成类型说明符所表示的类型。自动转换是在源类型和目标类型兼容以及目标类型广于源类型时发生一个类型到另一类的转换。例如: (float) a 把a转换为实型,(int)(x+y) 把x+y的结果转换为 整型 。在使用 强制转换 时应注意以下问题: 2 注意事项 编辑 1.类型说明符和 表达式 都必须加括号(单个 变量 可以不加括号),如把(int)(x+y)写成(int)x+y则成了把x转换成int型之后再与y相加了。 2.无论是 强制转换 或是自动转换,都只是为了本次运算的需要而对 变量 的数据长度进行的临时性转换,而不改变数据说明时对该 变量 定义的类型。 例1: main() { float f=5.75; printf("f=%d,f=%f\n",(int)f,f); } f=5,f=5.750000 将float f 强制转换 成int f float f=5.75;printf("(int)f=%d,f=%f\n",(int)f

TEA对称加密算法

安稳与你 提交于 2020-01-13 03:22:55
  今天在看 《Distributed Systems Concepts and Design》 这本书的时候,在讲到分布式系统的安全性的时候,给出了TEA算法,书本上有现成的代码,所以摘录下来以备后用。下面摘自百度百科的简短介绍:   TEA算法由剑桥大学计算机实验室的David Wheeler和Roger Needham于1994年发明[3]。它是一种分组密码算法,其明文密文块为64比特,密钥长度为128比特。TEA算法利用不断增加的Delta(黄金分割率)值作为变化,使得每轮的加密是不同,该加密算法的迭代次数可以改变,建议的迭代次数为32轮。   加密算法代码如下: 1 void encrypt(unsigned long k[], unsigned long text[]) 2 { 3 unsigned long y = text[0]; 4 unsigned long z = text[1]; 5 unsigned long delta = 0X9E3779B9; 6 unsigned long sum = 0; 7 int n; 8 9 for(n = 0; n < 32; n++) 10 { 11 sum += delta; 12 y += ((z << 4) + k[0]) ^ (z + sum) ^ ((z >> 5) + k[1]); 13 z += ((y <

详解C语言的类型转换

ぐ巨炮叔叔 提交于 2020-01-12 15:17:26
1.自动类型转换 字符型变量的值实质上是一个8位的整数值,因此取值范围一般是-128~127,char型变量也可以加修饰符unsigned,则unsigned char 型变量的取值范围是0~255(有些机器把char型当做unsighed char型对待, 取值范围总是0~255)。 如果一个运算符两边的运算数类型不同,先要将其转换为相同的类型,即较低类型转换为较高类型,然后再参加运算,转换规则如下图所示。 图中 横向箭头表示必须的转换 ,如两个float型数参加运算,虽然它们类型相同,但仍要先转成double型再进行运算,结果亦为double型。 纵向箭头表示当运算符两边的运算数为不同类型时的转换 ,如一个long 型数据与一个int型数据一起运算,需要先将int型数据转换为long型, 然后两者再进行运算,结果为long型。 所有这些转换都是由系统自动进行的, 使用时你只需从中了解结果的类型即可。 这些转换可以说是自动的,当然,C语言也提供了以显式的形式强制转换类型的机制。 当较低类型的数据转换为较高类型时,一般只是形式上有所改变, 而不影响数据的实质内容, 而较高类型的数据转换为较低类型时则可能有些数据丢失。 在进行自动类型转换的时候,如果原来的数是无符号数,那么在扩展的时候,高位填充的是0;如果是有符号数,那么高位填充的时符号位! 2.赋值中的类型转换

Does VB6 support unsigned data types?

浪尽此生 提交于 2020-01-12 08:01:31
问题 In order to settle a bet with one of my colleagues, I would like to find out if VB6 natively supports any unsigned data types. I believe the answer to be "no", but I can't seem to find any official documentation confirming that. A simple link to a Microsoft document would be an acceptable answer; an historical justification as to why such types are not supported would be an added bonus. 回答1: As Kris said, they're not supported, except for the Byte datatype, which is only available as unsigned

赋值中的强制类型转换

被刻印的时光 ゝ 提交于 2020-01-12 07:17:27
赋值中的类型转换 当 赋值运算符 两边的运算对象类型不同时,将要发生类型转换, 转换的规则是:把赋值运算符右侧 表达式 的类型转换为左侧 变量 的类型。具体的转换如下: (1) 浮点型 与 整型 ● 将浮点数(单双精度)转换为整数时,将舍弃浮点数的小数部分(是直接舍弃,编译器不会自动四舍五入), 只保留整数部分。将 整型 值赋给 浮点型 变量,数值不变,只将形式改为浮点形式, 即小数点后带若干个0。注意:赋值时的类型转换实际上是强制的。 (2) 单、 双精度浮点型 ● 由于C语言中的浮点值总是用双精度表示的,所以float 型数据只是在尾部加0延长为double型数据参加运算,然后直接赋值。double型数据转换为float型时,通过截尾数来实现,截断前要进行四舍五入操作。 (3) char型与int型 ● int型数值赋给char型 变量 时,只保留其最低8位,高位部分舍弃。 ● char型数值赋给int型 变量 时, 一些 编译程序 不管其值大小都作正数处理,而另一些编译程序在转换时,若char型数据值大于127,就作为负数处理。对于使用者来讲,如果原来char型数据取正值,转换后仍为正值;如果原来char型值可正可负,则转换后也仍然保持原值, 只是数据的内部表示形式有所不同。 (4) int型与long型 ● long型数据赋给int型 变量 时,将低16位值送给int型变量

C语言实现ping命令(一)

霸气de小男生 提交于 2020-01-11 18:57:04
ping命令使用到了网络中的ICMP协议: 关于ICMP介绍看这里: https://www.cnblogs.com/wanghao-boke/p/11670473.html 网络地址信息 地址信息表示: 网络传输时地址信息包括: 地址族(基于IPV4还是IPv6的地址族) IP地址 端口号 使用相关结构体来纪录地址信息: struct sockaddr_in{ sa_family_t sin_family; // 地址族 uint16_t sin_port; // 端口号 struct in_addr sin_addr; // 32位IP地址 char sin_zero[8]; // 不使用 }; struct in_addr{ in_addr_t s_addr; // 32位IP地址 }; struct in_addr{ in_addr_t s_addr; // 32位IP地址 }; #define in_addr_t uint32_t //无符号整型32位 还可以使用以下结构体: struct sockaddr{ sa_family_t sin_family; // 地址族 char sa_data[14]; // IP地址和端口 }; 成员sa_data保存的信息包含IP地址和端口号,剩余部分填充0。 在使用时定义信息地址时使用struct sockaddr_in结构体