sizeof的实现
来源:互联网 发布:淘宝直播卖衣服在哪里 编辑:程序博客网 时间:2024/05/18 01:50
//关于模拟sizeof函数实现计算类型大小
//查了很多资料,也用过模板
//但都无法获得对象的类型
//下面是一个用宏来实现的方法
#define my_sizeof(L_Value) ( /
(char *)(&L_Value + 1) - (char *)&L_Value /
)
#include <stdio.h>
#include <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;
}
//模板的类型操作
#include<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 /
)
#include <stdio.h>
#include <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;
}
//模板的类型操作
#include<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的实现
- Java的Sizeof实现
- Java的Sizeof实现
- Java的Sizeof实现
- 有关sizeof()的实现
- Java的Sizeof实现
- 模仿sizeof的实现方法
- c/c++ sizeof的实现
- <1>sizeof()的实现
- sizeof 实现
- sizeof 实现
- 实现 sizeof
- strlen和sizeof的实现原理分析
- Search Bar On Browser_2
- MSN messenger 80048820 错误 不能登陆 解决办法
- Search Bar On Browser_3
- 关于富爸爸
- Window.onload与body.onload
- sizeof的实现
- Search Bar On Browser_4
- 为人处事
- iBATIS for Java 2.3.0 Released (译)
- Search Bar On Browser_5
- 管理外协人员的困惑
- 忍不住想说几个CSDN博客的BUG
- 感受设计,感受生活
- 网络负载均衡[转载]