Chinaunix首页 | 论坛 | 博客
  • 博客访问: 105294
  • 博文数量: 23
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 235
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-19 22:44
文章分类

全部博文(23)

文章存档

2011年(1)

2008年(1)

2007年(21)

我的朋友
最近访客

分类: LINUX

2007-09-26 12:52:18

#include <stdio.h>
//#include "gcc4_debug.h"


#define PS(str,x) printf("Memsize %5d bytes - sizeof "#str"\n", sizeof(x));

void test_size1(int a[100])
{
    PS((Func-test_size1(char a[100]){printf sizeof(a);}), a);
}


int main()
{
        int a1;
        int *p1;
        int a2[100];
        int *p2[100];
        struct A3
        {
                int i;
                char p;
        }a3;
        union A4
        {
                int i;
                char p;
        }a4;
        struct A3 *p3;
        union A4 *p4;
        char *p5 = "123456";
        char p6[] = {'1','2','3','4','5','6'};

        PS((int a1),a1);
        PS((int a2[100]),a2);
        PS((struct A3{int i;char p;}),a3);
        PS((union A4{int i;char p;}),a4);
        PS((int *p1),p1);
        PS((int *p2[100]),p2);
        PS((struct A3 *p3),p3);
        PS((union A4 *p3),p4);
        PS((char *p5 = "123456"),p5);
        PS((char p6 = ['1','2','3','4','5','6']),p6);
        test_size1(a2);

}
                


 


x86上面32bMemsize     4 bytes - sizeof (int a1)
Memsize   400 bytes - sizeof (int a2[100])
Memsize     8 bytes - sizeof (struct A3{int i;char p;})
Memsize     4 bytes - sizeof (union A4{int i;char p;})
Memsize     4 bytes - sizeof (int *p1)
Memsize   400 bytes - sizeof (int *p2[100])
Memsize     4 bytes - sizeof (struct A3 *p3)
Memsize     4 bytes - sizeof (union A4 *p3)
Memsize     4 bytes - sizeof (char *p5 = "123456")
Memsize     6 bytes - sizeof (char p6 = ['1','2','3','4','5','6'])
Memsize     4 bytes - sizeof (Func-test_size1(char a[100]){printf sizeof(a);})


阅读(2008) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~