ARRAYSIZE宏与RtlpNumberOf的区别

来源:互联网 发布:淘宝投资要多少钱 编辑:程序博客网 时间:2024/06/06 10:47
// test_RtlpNumberOf.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <Windows.h>template<typename T, long N>long f1(T (&t)[N]){//typedef T zz;//typedef T zz[N];//zz a;return sizeof(t);/*for(long i=0; i<N; i++){printf("%c\n", t[i]);}*/}struct X{char s1:2;char s2:3;char s3:3;char s;};void foo(char (&ary)[100]){printf("%d",sizeof(ary));}int _tmain(int argc, _TCHAR* argv[]){char ary[10];char*p = ary;printf("sizeof(ary)=%d\n", sizeof(ary));//printf("ARRAYSIZE(p)=%d", ARRAYSIZE(p));printf("RtlpNumberOf(p)=%d\n", sizeof(RtlpNumberOf(ary)));char ch[64] = "hello world!!!!";printf("%d\n",f1(ch));char szBufs[100] = {0};foo(szBufs);return 0;}

本质上,是通过C++的引用技术(C语言不支持)来传递一个数组的引用而已。

0 0
原创粉丝点击