unsigned

nginx源码解析之常用数据结构

不问归期 提交于 2020-01-11 15:56:07
  1、基础数据结构(src/core目录)   1)ngx_list_t(ngx_list.h) typedef struct ngx_list_part_s ngx_list_part_t; // 描述链表的一个元素(数组) struct ngx_list_part_s { void *elts; // 数组的起始地址 ngx_uint_t nelts; // 数组当前已使用了多少容量 ngx_list_part_t *next; // 下一个链表元素ngx_list_part_t的地址 }; typedef struct { ngx_list_part_t *last; // 指向链表的最后一个数组元素 ngx_list_part_t part; // 链表的首个数组元素 size_t size; // 存储的每个数据的字节数必须小于或等于size ngx_uint_t nalloc; // 每个ngx_list_part_t数组的容量 ngx_pool_t *pool; // 链表中管理内存分配的内存池对象 } ngx_list_t; // 描述整个链表   相关接口:   ngx_list_create(): 创建新的链表。   ngx_list_init(): 初始化一个已有的链表。返回 NGX_OK 表示成功,返回 NGX_ERROR 表示失败。   ngx_list

C语言 动态数组实现

梦想的初衷 提交于 2020-01-11 15:54:12
一、概述 C语言是不能直接定义动态数组的,数组必须在初始化时确定长度。 如果要在程序运行时才确定数组的长度,就需要在运行的时候,自己去向系统申请一块内存用动态内存分配实现动态数组。 二、动态内存分配函数 1、malloc()函数 void *malloc(unsigned int size) 分配size个字节的内存空间,返回地址的指针,如果内存不够分,就返回空指针NULL。 注意:返回的指针是没有类型的,所以要使用得强制类型转换。 2、calloc()函数 void *calloc(unsigned int num, unsigned int size) 这个也是申请动态内存空间,不过就是分开了而已。 一共申请num个长度为size字节的内存空间。 3、free()函数 void free(void *p) 释放指针p内存空间。 这个很重要!!!!很重要!!!重要!!! 4、realloc()函数 void *realloc(void *p, unsigned int size) 给指针p申请的存储空间改为size个字节,返回的是存储空间首地址(指针) 三、动态数组实现 1、一维动动数组实现 dynamicArrayOneDimensional.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

What is the deal with assigning an unsigned variable to a signed value?

☆樱花仙子☆ 提交于 2020-01-11 14:12:28
问题 This code I am looking at has a lot of places where I see things like this happening: char *functionName(char *passedVariable) { unsigned char *newVariable = (char* ) passedVariable; Why is this being done? I always try to be consistent in the use of signed/unsigned, because I know that switching between the two can cause problems, but this developer doesn't seem to care. 回答1: Changing the pointer type is not really an issue, this address will still be valid. However interpreting the pointed

What is the deal with assigning an unsigned variable to a signed value?

六眼飞鱼酱① 提交于 2020-01-11 14:12:09
问题 This code I am looking at has a lot of places where I see things like this happening: char *functionName(char *passedVariable) { unsigned char *newVariable = (char* ) passedVariable; Why is this being done? I always try to be consistent in the use of signed/unsigned, because I know that switching between the two can cause problems, but this developer doesn't seem to care. 回答1: Changing the pointer type is not really an issue, this address will still be valid. However interpreting the pointed

《C++Primer Plus》学习笔记 | 第3章 处理数据

笑着哭i 提交于 2020-01-11 05:49:04
第3章 处理数据 3.1 简单变量 程序必须记录信息的3个基本属性: –> 声明一个变量 信息将存储在哪里 要存储什么值 存储何种类型的信息 3.1.1 变量名 C++命名规则: 在名称中只能使用字母字符、数字和下划线 名称的第一个字符不能是数字 区分大写字符与小写字符 不能将C++关键字用作名称 以两个下划线或下划线和大写字母打头的名称被保留给实现(编译器及其使用的资源)使用。 以一个下划线开头的名称被保留给实现,用作全局标识符。 C++对于名称的长度没有限制,名称中所有的字符都有意义,但有些平台有长度限制。 编程中的命名方式和常用命名名称 3.1.2 整型 3.1.3 整型short、int、long和 long long 计算机内存由一些叫做位bit的单元组成。 short至少16位 int至少与short一样长 long至少32位,且至少与int一样长 long long至少64位,且至少与long一样长 实际上,short是short int的简称,而long是long int的简称。 字节byte通常指的是8位的内存单元。 字节指的就是描述计算机内存量的度量单位。 1KB == 1024byte 1MB == 1024KB 1 运算符sizeof和头文件limits sizeof 运算符返回类型或变量的长度,单位为字节。

用openssl库RSA加密解密

倖福魔咒の 提交于 2020-01-11 03:41:12
1 #include <stdio.h> 2 #include <openssl/rsa.h> 3 #include <openssl/pem.h> 4 #include <openssl/err.h> 5 6 //加密 7 int my_encrypt(const char *input, int input_len, char *output, int *output_len, const char *pri_key_fn) 8 { 9 RSA *p_rsa = NULL; 10 FILE *file = NULL; 11 int ret = 0; 12 13 if((file = fopen(pri_key_fn, "rb")) == NULL) 14 { 15 ret = -1; 16 goto End; 17 } 18 19 if((p_rsa = PEM_read_RSAPrivateKey(file, NULL,NULL,NULL )) == NULL) 20 { 21 ret = -2; 22 goto End; 23 } 24 25 if((*output_len = RSA_private_encrypt(input_len, (unsigned char*)input, (unsigned char*)output, p_rsa, RSA_PKCS1

MISRA C:2004, error with bit shifting

我怕爱的太早我们不能终老 提交于 2020-01-11 03:14:29
问题 I'm using IAR Workbench compiler with MISRA C:2004 checking on. The fragment is: #define UNS_32 unsigned int UNS_32 arg = 3U; UNS_32 converted_arg = (UNS_32) arg; /* Error line --> */ UNS_32 irq_source = (UNS_32)(1U << converted_arg); The MISRA error is: Error[Pm136]: illegal explicit conversion from underlying MISRA type "unsigned char" to "unsigned int" (MISRA C 2004 rule 10.3) I don't see any unsigned char in any of the code above. The discussion at Why did Misra throw an error here?

QT中显示图像数据

痴心易碎 提交于 2020-01-11 02:53:00
博客转载自:https://blog.csdn.net/lg1259156776/article/details/52325091 一般图像数据都是以RGBRGBRGB……字节流的方式(解码完成后的原始图像流),我说成字节流,那就表明R,G,B的值各占一个字节,在编程时表示的就是unsigned char * data。我们先来看一下QT中的QImage对象。在加载data数据前,我们要确定QImage加载图像的空间分配足够大,先假设data是由640*480像素的压缩数据解码得来的,RGB(3字节)是一个像素,故data的应该是640*480*3个字节;比较一下下面两种方式: QImage img(640,480,QImage::Format_RGB888); unsigned char * p_bits = img.bits(); 24位(3字节)一个像素,那么p_bits所得到的空间应该是640*480*3个字节,所以刚刚好一个字节对一个字节。所以我们这样赋值即可: for(int i=0;i<640*480*3;i+=3) { puiBits[i]=data[i]; puiBits[i+1]=data[i+1]; puiBits[i+2]=data[i+2]; } 接着就是将img转化成QPixmap填充到QWidget QPixmap pixmap=QPixmap:

Why compiler is not giving error when signed value is assigned to unsigned integer? - C++

二次信任 提交于 2020-01-10 00:52:11
问题 I know unsigned int can't hold negative values. But the following code compiles without any errors/warnings. unsigned int a = -10; When I print the variable a , I get a wrong value printed. If unsigned variables can't hold signed values, why do compilers allow them to compile without giving any error/warning? Any thoughts? Edit Compiler : VC++ compiler Solution Need to use the warning level 4. 回答1: Microsoft Visual C++: warning C4245: 'initializing' : conversion from 'int' to 'unsigned int',

51单片机流水灯

安稳与你 提交于 2020-01-09 23:54:49
三种方法实现流水灯 1.位输出操作 流程图 Created with Raphaël 2.2.0 开始 开发板初始化 LED0亮一秒后熄灭 LED1亮一秒后熄灭 LED2亮一秒后熄灭 LED3亮一秒后熄灭 LED4亮一秒后熄灭 LED5亮一秒后熄灭 LED6亮一秒后熄灭 LED7亮一秒后熄灭 代码 //位操作输出 # include <reg52.h> # define uint unsigned int # define on 0 # define off 1 sbit LED0 = P1 ^ 0 ; sbit LED1 = P1 ^ 1 ; sbit LED2 = P1 ^ 2 ; sbit LED3 = P1 ^ 3 ; sbit LED4 = P1 ^ 4 ; sbit LED5 = P1 ^ 5 ; sbit LED6 = P1 ^ 6 ; sbit LED7 = P1 ^ 7 ; void delay ( uint xms ) //延时约xms毫秒 { uint i , j ; for ( i = xms ; i > 0 ; i -- ) for ( j = 112 ; j > 0 ; j -- ) ; //分号代表跑空,for语句不需要分号,112次表示一毫秒 } void main ( ) { while ( 1 ) { LED0 = on ; //P1^0=0;