sizeof 的使用(标记一下)
2011-05-18 00:43
309 查看
#include <stdio.h> #include <stdlib.h> int main() { struct { int a ; char b ; int c ; } a,*b; int d; char f; float g; double h; printf("sizeof(a) = %d,sizeof(b) = %d ,sizeof(*b) = %d\n",sizeof(a),sizeof(b),sizeof(*b)); printf("sizeof(&d) = %d ,sizeof(&f) = %d ,sizeof(&g) = %d,sizeof(&h) = %d\n",sizeof(&d),sizeof(&f),sizeof(&g),sizeof(&h)); printf("sizeof(d) = %d ,sizeof(f) = %d ,sizeof(g) = %d,sizeof(h) = %d\n",sizeof(d),sizeof(f),sizeof(g),sizeof(h)); }上面程序输出的结果为:
sizeof(a) = 12,sizeof(b) = 8 ,sizeof(*b) = 12 sizeof(&d) = 8 ,sizeof(&f) = 8 ,sizeof(&g) = 8,sizeof(&h) = 8 sizeof(d) = 4 ,sizeof(f) = 1 ,sizeof(g) = 4,sizeof(h) = 8 在系统中 sizeof( char *)、sizeof( int *)、sizeof( float *)、sizeof( double *) 的长度均为8 所以在sizeof时千万要注意,使用不当会出现错误; 我的使用的是系统和编译器为: [code][struggle@struggle alloc]$ cc -v 使用内建 specs。 COLLECT_GCC=cc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.5.1/lto-wrapper 目标:x86_64-redhat-linux 配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,lto --enable-plugin --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux 线程模型:posix gcc 版本 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC) [struggle@struggle alloc]$ uname -a Linux struggle 2.6.35.13-91.fc14.x86_64 #1 SMP Tue May 3 13:23:06 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux [struggle@struggle alloc]$[/code]
相关文章推荐
- 好久不做开发了,最近使用vs2008遇到了不能添加多个项目的问题,在此标记一下
- iptables数据包、连接标记模块MARK/CONNMARK的使用(打标签)
- thinkphp3.2 删除Runtime目录里的缓存文件,标记一下,以下好找。
- 总结一下,以软件开发生命周期来说明不同的测试的使用情况
- C++面试题6:sizeof 使用规则及陷阱
- 在没有对象的情况下使用decltype和sizeof问题的解决方案
- 解释一下你对盒模型的理解,以及如何在 CSS 中告诉浏览器使用不同的盒模型来渲染你的布局。
- iOS学习之Map,定位,标记位置的使用
- net控件中数据导到Excel的格式 首先,我们了解一下excel从web页面上导出的原理。当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取它,所以把mime类型设为:application/vnd.ms-excel,当excel读取文件时会以每个cell的格式呈现数据,如果cell没有规定的格式,则excel会以默认的格式去呈现该cell的数据。这样就给我们提供了自定义数据格式的空间,当然我们必须使用excel支持的格式。下面就列出常用的一些格式: 1) 文本
- 翻译《有关编程、重构及其他的终极问题?》——9.使用'-0'符号作为结尾标记
- sizeof使用规则与陷阱分析
- C++ sizeof 使用规则及陷阱分析
- 记录一下PHP数组数据分页的方法 array_slice() 函数的使用
- 使用MFC开发ActiveX控件时修改注册表来标记控件为安全
- springboot 使用thymeleaf 模板引擎时报错org.xml.sax.SAXParseException: 元素类型 "link" 必须由匹配的结束标记 "</link>" 终止
- sqlreview工具收集(标记一下)
- 服务之间的http调用越来越多,下面把使用http连接池的注意事项及运遇到的坑和大家分享一下
- vim使用系列之二——总结一下自己常用的VIM操作(边用边更新, 2010.10.22)
- 使用Google工具栏百度一下
- 使用python实现标记图像感兴区域