gcc 变量类型大小 练习 远离 cygwin64 需要带dll
- /* testmini.c -- very simple test program for the miniLZO library
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <inttypes.h>
- #include <string.h>
- #ifndef uint8_t
- #define uint8_t unsigned char
- #endif
- typedef unsigned __int64 lzo_1;
- /* unsigned __int64 就是个无符号 64 整形。可能比你前面用的那些类型位数长一些。*/
- typedef __int64 lzo_2;
- typedef signed __int64 lzo_3;
- /* typedef lzo_ullong_t lzo_3;
- typedef lzo_llong_t lzo_4;*/
- typedef unsigned int lzo_5;
- typedef int lzo_6;
- typedef unsigned long lzo_7;
- typedef long lzo_8;
- typedef struct {
- lzo_1 lzo_11[1];
- } _context1;
- typedef struct {
- lzo_2 lzo_12[1];
- } _context2;
- typedef struct {
- lzo_5 lzo_15[1];
- } _context5;
- typedef struct {
- lzo_6 lzo_16[1];
- } _context6;
- typedef struct {
- lzo_7 lzo_17[1];
- } _context7;
- typedef struct {
- lzo_8 lzo_18[1];
- } _context8;
- /* 96 */
- typedef struct {
- uint8_t key[32];
- uint8_t enckey[32];
- uint8_t deckey[32];
- } aes256_context;
- /* 96 */
- struct student
- {
- char name[7];
- int id; // 类型出错
- char subject[5];
- } student __attribute__ ((aligned(4)));
- /* 20
- ---------8+4+8==20------
- */
- struct student1
- {
- char name[7];
- int id; // 类型出错
- char subject[5];
- } student1 __attribute__ ((packed));
- /*
- test.c:56:1: warning: 'packed' attribute ignored [-Wattributes]
- } student1 __attribute__ ((packed));
- */
- /* 20
- -------7+4+5==16---------
- */
- #pragma pack(push)
- #pragma pack(1)
- struct a1
- {
- short a;
- int b;
- char c;
- }A1;
- #pragma pack(pop)/*7 */
- struct a2
- {
- short a;
- int b;
- char c;
- }A2; /*12*/
- #pragma pack(2)
- struct c
- {
- char b;
- int a;
- short c;
- }C;
- #pragma pack() /*8 */
- #pragma pack(1)
- struct d
- {
- char b;
- int a;
- short c;
- }D;
- #pragma pack()/* 7 */
- /*
- struct stu3
- {
- short i;
- struct
- {
- char c;
- int j;
- } stu3_1;
- int k;
- }*/
- /*
- stu3_1最大成员为j,大小为4.因此c的偏移量为4的整数倍。所以实际上c的偏移量不为2,编译器会在i的后面补2字节,使c的偏移量为4.
- 总结:在定义结构体类型时需要考虑到字节对齐的情况,不同的顺序会影响到结构体的大小。
- ---------------------
- 作者:w狸猫
- 来源:CSDN
- 原文:https://blog.csdn.net/wangtong95/article/details/51451452
- 版权声明:本文为博主原创文章,转载请附上博文链接!
- */
- /*
- #ifndef PACK
- #define PACK __attribute__ ((packed))
- #endif
- struct a
- {
- char a;
- int b;
- }PACK A;
- */
- int main(int argc, char *argv[])
- { /*
- If your compiler isn't C99 compliant, get a different compiler. (Yes, I'm looking at you, Visual Studio.)
- PS: If you are worried about portability, don't use %lld. That's for long long, but there are no guarantees that long long actually is the same as _int64 (POSIX) or int64_t (C99).
- Edit: Mea culpa - I more or less brainlessly "search & replace"d the _int64 with int64_t without really looking at what I am doing. Thanks for the comments pointing out that it's uint64_t, not unsigned int64_t. Corrected.
- _Long128, int128_t and uint128_t
- could use uint64_t u64; sprintf( buf, "%llu", (unsigned long long) u64); as unsigned long long is at least 64 bits.
- You need to use %I64u with Visual C++.
- However, on most C/C++ compiler, 64 bit integer is long long. Therefore, adopt to using long long and use %llu.
- */
- lzo_1 dbFileSize = 18446744073709551615u;
- lzo_2 fileSize = -9223372036854775808;
- char buf[128];
- memset(buf, 0x00, 128);
- sprintf( buf, "\nOD DB File Size = %" PRId64 " bytes \t"
- " XML file size = %" PRIu64 " bytes\n"
- , fileSize, dbFileSize );
- printf( "The string is %s\n", buf );
- /*
- lzo_1 aaa1 = 18446744073709551615;
- lzo_2 aaa2 = -9223372036854775808;
- scanf('%lld',&aaa1);
- printf('%lld',aaa1);
- scanf('%lld',&aaa2);
- printf('%lld',aaa2);
- scanf('%I64d',&a);
- printf('%I64d',a);
- scanf('%lld',&a);
- printf('%lld',a);
- linux下是 printf("%llu\n",a); windows下应该是 %l64u吧,你试试看
- 使用无符号数时,将"%lld"改成"%llu"即可。
- printf("sizeof(_context1):%d\n",sizeof(_context1));
- printf("sizeof(_context2):%d\n",sizeof(_context2));
- printf("sizeof(_context5):%d\n",sizeof(_context5));
- printf("sizeof(_context6):%d\n",sizeof(_context6));
- printf("sizeof(_context7):%d\n",sizeof(_context7));
- printf("sizeof(_context8):%d\n",sizeof(_context8));
- printf("sizeof(student):%d\n",sizeof(student));
- printf("sizeof(student1):%d\n",sizeof(student1));
- printf("sizeof(A1):%d\n",sizeof(A1));
- printf("sizeof(A2):%d\n",sizeof(A2));
- printf("sizeof(aes256_context):%d\n",sizeof(aes256_context));
- printf("sizeof(c):%d\n",sizeof(C));
- printf("sizeof(d):%d\n",sizeof(D));
- sizeof(_context1):8
- sizeof(_context2):8
- sizeof(_context5):4
- sizeof(_context6):4
- sizeof(_context7):4
- sizeof(_context8):4
- sizeof(student):20
- sizeof(student1):20
- sizeof(A1):7
- sizeof(A2):12
- sizeof(aes256_context):96
- sizeof(c):8
- sizeof(d):7*/
- printf("\nminiLZO simple compression test passed.\n");
- return 0;
- }
- /*
- gcc -m32 -I. -s -Wall -O2 -fomit-frame-pointer -o test32 test.c
- gcc -m64 -I. -s -Wall -O2 -fomit-frame-pointer -o test64 test.c
- */
- /*
- 一:#pragma warning指令
- 该指令允许有选择性的修改编译器的警告消息的行为
- 指令格式如下:
- #pragma warning( warning-specifier : warning-number-list [; warning-specifier : warning-number-list...]
- #pragma warning( push[ ,n ] )
- #pragma warning( pop )
- 主要用到的警告表示有如下几个:
- once:只显示一次(警告/错误等)消息
- default:重置编译器的警告行为到默认状态
- 1,2,3,4:四个警告级别
- disable:禁止指定的警告信息
- error:将指定的警告信息作为错误报告
- 如果大家对上面的解释不是很理解,可以参考一下下面的例子及说明
- #pragma warning( disable : 4507 34; once : 4385; error : 164 )
- 等价于:
- #pragma warning(disable:4507 34) // 不显示4507和34号警告信息
- #pragma warning(once:4385) // 4385号警告信息仅报告一次
- #pragma warning(error:164) // 把164号警告信息作为一个错误。
- 同时这个pragma warning 也支持如下格式:
- #pragma warning( push [ ,n ] )
- #pragma warning( pop )
- 这里n代表一个警告等级(1---4)。
- #pragma warning( push )保存所有警告信息的现有的警告状态。
- #pragma warning( push, n)保存所有警告信息的现有的警告状态,并且把全局警告
- 等级设定为n。
- #pragma warning( pop )向栈中弹出最后一个警告信息,在入栈和出栈之间所作的
- 一切改动取消。例如:
- #pragma warning( push )
- #pragma warning( disable : 4705 )
- #pragma warning( disable : 4706 )
- #pragma warning( disable : 4707 )
- #pragma warning( pop )
- 在这段代码的最后,重新保存所有的警告信息(包括4705,4706和4707)
- 在使用标准C++进行编程的时候经常会得到很多的警告信息,而这些警告信息都是不必要的提示,
- 所以我们可以使用#pragma warning(disable:4786)来禁止该类型的警告
- 在vc中使用ADO的时候也会得到不必要的警告信息,这个时候我们可以通过
- #pragma warning(disable:4146)来消除该类型的警告信息
- 二:#pragma pack()
- 注:如果设置的值比结构体中字节最长的类型还要大,则这个变量(注意仅针对这一个变量)只按照它的字节长度对齐,即不会出现内存浪费的情况。请参见(4)。
- (1)
- #pragma pack(1) //每个变量按照1字节对齐
- struct A
- {
- char x; //aligned on byte boundary 0
- int y; //aligned on byte boundary 1
- }a;
- sizeof(a)==5
- (2)
- #pragma pack(2) //每个变量按照2字节对齐
- struct A
- {
- char x; //aligned on byte boundary 0
- int y; //aligned on byte boundary 2
- }a;
- sizeof(a)==6
- (3)
- #pragma pack(4) //每个变量按照4字节对齐
- struct A
- {
- char x; //aligned on byte boundary 0
- int y; //aligned on byte boundary 4
- }a;
- sizeof(a)==8
- (4)
- #pragma pack() //默认,相当于#pragma pack(8) 每个变量按照8字节对齐
- struct A
- {
- char x; //aligned on byte boundary 0
- int y; //aligned on byte boundary 4
- }a;
- sizeof(a)==8
- 但是这里y的大小是4字节,所以不会按照8字节对齐,否则将造成1个int空间的浪费
- 三.#pragma comment
- The following pragma causes the linker to search for the EMAPI.LIB library while linking. The linker searches first in the current working directory and then in the path specified in the LIB environment variable:
- #pragma comment( lib, "emapi" )
- 四.#pragma deprecated
- When the compiler encounters a deprecated symbol, it issues C4995:
- void func1(void) {}
- void func2(void) {}
- int main() {
- func1();
- func2();
- #pragma deprecated(func1, func2)
- func1(); // C4995
- func2(); // C4995
- }
- 五.#pragma message
- The following code fragment uses the message pragma to display a message during compilation:
- #if _M_IX86 == 500
- #pragma message( "Pentium processor build" )
- #endif
- */
编译参数
gcc -m32 -s -Wall -O2 -fomit-frame-pointer -c minilzo.c -o gcc32.o
gcc -m64 -s -Wall -O2 -fomit-frame-pointer -c minilzo.c -o gcc32.o
gcc 变量类型大小 练习 远离 cygwin64 需要带dll的更多相关文章
- c语言中的数据变量类型,大小
C中有哪些数据类型? 回答: 有两种类型的数据类型,用户定义和预定义.预定义的数据类型是int,char,float,double等,用户使用标签struct,union或enum创建用户定义的数据类 ...
- C语言各类型大小,结构体大小 sizeof(struct A)
C语言类型大小总览 编译器pack指令 #pragma pack(n)——定义n字节对齐 C++固有类型的对齐取编译器对齐与自身大小中较小的一个 32位C++默认8字节对齐.gcc编译器默认4字节对齐 ...
- C语言的类型大小
C语言的类型大小 设计程序的时候我们一般会考虑的尽量的周全,尤其是像C这样的静态类型语言. 有一些溢出的问题就源于没有搞清楚变量的大小范围,所以我们编写的时候需要特别注意 C的整形(整数类型)大小 C ...
- C++数据类型和变量类型。
数据类型 数字是自由的[不只属于某个类型]!但是它可以有不同的身份!int.char.float.double等身份.它以不同的身份[存储规则]存储在内存的某个位置内部! 变量类型 内存编号是不会变的 ...
- CUDA1.1-函数类型限定符与变量类型限定符
这部分来自于<CUDA_C_Programming_Guide.pdf>,看完<GPU高性能变成CUDA实战>的第四章,觉得这本书还是很好的,是一种循序渐进式的书,值得看,而不 ...
- 20151010 C# 第一篇 变量类型
20151010 变量类型: 1. 值类型:变量本身直接存储数据 整数类型:代表没有小数点的整数数值 类型 说明 范围 sbyte 8位有符号整数 -128——127 short 16位有符号整数 - ...
- 深入理解计算机各种类型大小(sizeof)
深入理解计算机各种类型大小(sizeof) // Example of the sizeof keyword size_t i = sizeof( int ); struct align_dep ...
- 【C语言探索之旅】 第二部分第六课:创建你自己的变量类型
内容简介 1.课程大纲 2.第二部分第六课: 创建你自己的变量类型 3.第二部分第七课预告: 文件读写 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C ...
- Python中的高级变量类型
高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数字型 和 非数字型 数字型 整型 (int) 浮点型(float) 布尔型(bool) ...
随机推荐
- 让 Ocelot 与 asp.net core “共存”
让 Ocelot 与 asp.net core "共存" Intro 我们的 API 之前是一个单体应用,各个模块的服务是通过 Assembly 集成在一起,最后部署在一个 web ...
- 洛谷 - P1034 - 矩形覆盖 - dfs
https://www.luogu.org/problemnew/show/P1034 可能是数据太水了瞎搞都可以过. 判断两个平行于坐标轴的矩形相交(含顶点与边相交)的代码一并附上. 记得这里的xy ...
- SCUT - 244 - 全新的游戏 - 凸包
https://scut.online/p/244 除了常规的求凸包求面积,还有一个判断点在凸包内,先找出点所在的三角扇区. #include<bits/stdc++.h> using n ...
- poj1477(水)
犯了一个错误,贡献了一次CE: G++里面没有头文件,用scanf会CE:然而C++就可以. 两大cow解释: 最好不要c 的输入和c++的一起用 (特别是关同步的时候) 然而好像他们也不是很了解.. ...
- python __builtins__ tuple类 (68)
68.'tuple', 转换为元组类型 class tuple(object) | tuple() -> empty tuple | tuple(iterable) -> tuple in ...
- 查看软件安装的位置 Ubuntu
Ubuntu和windows不一样,不是所有的软件都在一个文件夹,而是不同类型的分散在不同的文件夹下 所以查找起来也是不同的 如果知道是用 apt-get install 方法安装的,可以直接用 dp ...
- smtplib报警模块
#!/usr/bin/env python # coding:utf-8 import time import subprocess import smtplib from email.mime.te ...
- Codeforces Round #542(Div. 2) D1.Toy Train
链接:https://codeforces.com/contest/1130/problem/D1 题意: 给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果. 求从 ...
- Palindromes in a Tree CodeForces - 914E
https://vjudge.net/problem/CodeForces-914E 点分就没一道不卡常的? 卡常记录: 1.把不知道为什么设的(unordered_map)s换成了(int[])s ...
- Xor-sequences CodeForces - 691E || 矩阵快速幂
Xor-sequences CodeForces - 691E 题意:在有n个数的数列中选k个数(可以重复选,可以不按顺序)形成一个数列,使得任意相邻两个数异或的结果转换成二进制后其中1的个数是三的倍 ...