/* 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的更多相关文章

  1. c语言中的数据变量类型,大小

    C中有哪些数据类型? 回答: 有两种类型的数据类型,用户定义和预定义.预定义的数据类型是int,char,float,double等,用户使用标签struct,union或enum创建用户定义的数据类 ...

  2. C语言各类型大小,结构体大小 sizeof(struct A)

    C语言类型大小总览 编译器pack指令 #pragma pack(n)——定义n字节对齐 C++固有类型的对齐取编译器对齐与自身大小中较小的一个 32位C++默认8字节对齐.gcc编译器默认4字节对齐 ...

  3. C语言的类型大小

    C语言的类型大小 设计程序的时候我们一般会考虑的尽量的周全,尤其是像C这样的静态类型语言. 有一些溢出的问题就源于没有搞清楚变量的大小范围,所以我们编写的时候需要特别注意 C的整形(整数类型)大小 C ...

  4. C++数据类型和变量类型。

    数据类型 数字是自由的[不只属于某个类型]!但是它可以有不同的身份!int.char.float.double等身份.它以不同的身份[存储规则]存储在内存的某个位置内部! 变量类型 内存编号是不会变的 ...

  5. CUDA1.1-函数类型限定符与变量类型限定符

    这部分来自于<CUDA_C_Programming_Guide.pdf>,看完<GPU高性能变成CUDA实战>的第四章,觉得这本书还是很好的,是一种循序渐进式的书,值得看,而不 ...

  6. 20151010 C# 第一篇 变量类型

    20151010 变量类型: 1. 值类型:变量本身直接存储数据 整数类型:代表没有小数点的整数数值 类型 说明 范围 sbyte 8位有符号整数 -128——127 short 16位有符号整数 - ...

  7. 深入理解计算机各种类型大小(sizeof)

    深入理解计算机各种类型大小(sizeof)   // Example of the sizeof keyword size_t  i = sizeof( int ); struct align_dep ...

  8. 【C语言探索之旅】 第二部分第六课:创建你自己的变量类型

    内容简介 1.课程大纲 2.第二部分第六课: 创建你自己的变量类型 3.第二部分第七课预告:   文件读写 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C ...

  9. Python中的高级变量类型

    高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数字型 和 非数字型 数字型 整型 (int) 浮点型(float) 布尔型(bool) ...

随机推荐

  1. js跳转方法整理与自动刷新

    js方式的页面跳转1.window.location.href方式 <script language="JavaScript" type="text/javascr ...

  2. python 迭代器 Iterator

    一.可迭代对象定义 可以直接作用于for循环的数据类型有以下几种: 一类是集合数据类型,如list.tuple.dict.set.str.bytes.bytearray等: 一类是generator, ...

  3. IT兄弟连 JavaWeb教程 Servlet中定义的变量的作用域类型

    在Java语言中,局部变量和实力变量有着不同的作用于,它们的区别如下: 局部变量在一个方法中定义,每当一个线程执行局部变量所在的方法时,在线程的堆栈中就会创建这个局部变量,当线程执行完该方法,局部变量 ...

  4. Python 字符串太长分行写

    原文:https://blog.csdn.net/peng__dada/article/details/79138135 #第一种:三个单引号 print '''我是一个程序员       我刚开始学 ...

  5. JSP | 基础 | 新建Hello world 的三种方式

    第一种: 直接写一个 test.jsp 文件到ROOT文件目录下,内容如下,访问 “http://localhost:8080/test.jsp” <%-- Licensed to the Ap ...

  6. Headmaster's Headache UVA - 10817

    UVA-10817 ans[i][s1][s2]表示考虑前i个人时,有至少1人教的科目集合为s1,有至少2人教的科目集合为s2时的最少工资集合用一个数字表示,转换成二进制后从后面开始数第i位的状态(1 ...

  7. mongoDB内置文档定义

    在最近的设计数据库时,犯了一个低级的错误,就是设置内置文档是定义了错误了,导致数据取不出,去找了很多资料都无法解决.最后看了一了一下自己设置的model文件.配置错误,所以导致数据取不出了. 数据库时 ...

  8. Intent实现界面跳转、程序跳转

    一个程序往往由多个界面组成,界面之间的跳转,实质是Activity之间的跳转. 从当前程序跳转到其它程序,实质是启动了目标程序的入口Activity. Intent被称为意图,常用于组件之间的交互,可 ...

  9. Macbook air 上打开cocoscreator出错

    Error: EROFS: read-only file system, open '/Volumes/Cocos Creator/CocosCreator.app/Contents/Resource ...

  10. jquery实现上传图片及图片大小验证、图片预览效果代码

    jquery实现上传图片及图片大小验证.图片预览效果代码 jquery实现上传图片及图片大小验证.图片预览效果代码 上传图片验证 */ function submit_upload_picture() ...