sizeof的实现
来源:百度文库 编辑:神马文学网 时间:2024/04/28 20:16:48
sizeof的实现 jerry 发表于 2008-5-15 15:06:00
0 推荐 //关于模拟sizeof函数实现计算类型大小
//查了很多资料,也用过模板
//但都无法获得对象的类型
//下面是一个用宏来实现的方法
#define my_sizeof(L_Value) ( \
(char *)(&L_Value + 1) - (char *)&L_Value \
)
#i nclude
#i nclude
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
using namespace std;
template
int LengthOfArray(Any * p)
{
return int(p+1) - int(p);
}
int main()
{
double * q;
char a[10];
cout << LengthOfArray(q)< cout << LengthOfArray(&a)<
return 0;
}
0 推荐 //关于模拟sizeof函数实现计算类型大小
//查了很多资料,也用过模板
//但都无法获得对象的类型
//下面是一个用宏来实现的方法
#define my_sizeof(L_Value) ( \
(char *)(&L_Value + 1) - (char *)&L_Value \
)
#i nclude
#i nclude
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
using namespace std;
template
int LengthOfArray(Any * p)
{
return int(p+1) - int(p);
}
int main()
{
double * q;
char a[10];
cout << LengthOfArray(q)<
return 0;
}
sizeof的实现
用sizeof来实现编译时的类型辨别 — Windows Live
关于sizeof的问题
sizeof
sizeof
结构体(含位域)的sizeof
关于c下面的sizeof()
Sizeof与Strlen的区别与联系
sizeof,strlen
关于Sizeof
字符数组,字符指针,Sizeof总结(转载) - 小团的日志 - 网易博客
比较sizeof()与strlen()
sizeof使用场合
sizeof,终极无惑
sizeof用法分析
sizeof用法分析1
深入理解sizeof
sizeof 操作符详解
解析C语言中的sizeof
解析C语言中的sizeof
无法实现的誓言
关于UDDI的实现
实现对外开放的可持续发展
实现个人的可持续发展