sizeof 实现
来源:互联网 发布:java面试项目经验介绍 编辑:程序博客网 时间:2024/06/08 05:20
//关于模拟sizeof函数实现计算类型大小
//查了很多资料,也用过模板
//但都无法获得对象的类型
//下面是一个用宏来实现的方法
#define my_sizeof(L_Value) ( /
(char *)(&L_Value + 1) - (char *)&L_Value /
)
#i nclude <stdio.h>
#i nclude <stdio.h>
int main(void){
int i;
double f;
double a[4];
double *p;
printf("%d/n", my_sizeof(i));
printf("%d/n", my_sizeof(f));
printf("%d/n", my_sizeof(a));
printf("%d/n", my_sizeof(p));
printf("%d/n", my_sizeof("abdegh"));
return 0;
}
//模板的类型操作
#i nclude<iostream>
using namespace std;
template<class Any>
int LengthOfArray(Any * p)
{
return int(p+1) - int(p);
}
int main()
{
double * q;
char a[10];
cout << LengthOfArray(q)<<endl;
cout << LengthOfArray(&a)<<endl;
return 0;
}
//查了很多资料,也用过模板
//但都无法获得对象的类型
//下面是一个用宏来实现的方法
#define my_sizeof(L_Value) ( /
(char *)(&L_Value + 1) - (char *)&L_Value /
)
#i nclude <stdio.h>
#i nclude <stdio.h>
int main(void){
int i;
double f;
double a[4];
double *p;
printf("%d/n", my_sizeof(i));
printf("%d/n", my_sizeof(f));
printf("%d/n", my_sizeof(a));
printf("%d/n", my_sizeof(p));
printf("%d/n", my_sizeof("abdegh"));
return 0;
}
//模板的类型操作
#i nclude<iostream>
using namespace std;
template<class Any>
int LengthOfArray(Any * p)
{
return int(p+1) - int(p);
}
int main()
{
double * q;
char a[10];
cout << LengthOfArray(q)<<endl;
cout << LengthOfArray(&a)<<endl;
return 0;
}
- sizeof 实现
- sizeof 实现
- 实现 sizeof
- sizeof的实现
- sizeof()的实现.
- sizeof的实现
- sizeof的实现
- sizeof()的实现
- 实现sizeof功能
- Sizeof的实现
- Java的Sizeof实现
- sizeof函数实现
- sizeof C 实现
- Java的Sizeof实现
- Java的Sizeof实现
- 有关sizeof()的实现
- Java的Sizeof实现
- Java中实现sizeof详述
- boost::pool与内存池技术
- Kademlia详解
- 远程访问数据库
- c#经典入门学习笔记-定义集合
- 技术平台研发目标
- sizeof 实现
- 对漂亮女孩的追求策略
- deeply understand pointer in C
- 我与Oracle数据库11g的亲密接触
- 我与Oracle数据库11g的亲密接触
- 四年时光双空空!
- linux内核的文件描述
- 程序员四大忌
- 和和的区别