论坛首页 编程语言技术论坛

高效率的c++之如何分析网络数据包之struct关键技术

浏览 2409 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2009-12-24   最后修改:2009-12-24
C++
// Win32ConsoleMemoryTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;
struct B
{
	int j;
};
struct A
{
	int i;
	B b[0];
};
template<int a> class BT
{
public:
	BT()
		:size(a)
	{
	}
	int size;
};

int _tmain(int argc, _TCHAR* argv[])
{
	const int i = sizeof(B);
	BT<i> bt;
	cout<<bt.size<<endl;
	A a;
	a.i = 1;
	B b1;
	b1.j = 2;
	B b2;
	b2.j = 3;
	A* pA = (A*)(malloc(sizeof(A) + 2*sizeof(B))); 
	memcpy((char*)pA + sizeof(A) ,&b1,sizeof(B));
	memcpy((char*)pA + sizeof(A) + sizeof(B),&b2,sizeof(B));
	cout<<(pA->b[0].j)<<endl;
	cout<<(pA->b[1].j)<<endl;
	cin.get();
}

 

   发表时间:2009-12-25  
.....关键技术,差点没吓死。。
0 请登录后投票
   发表时间:2009-12-25  
ray_linn 写道
.....关键技术,差点没吓死。。

高手,这都被你发现啦。
0 请登录后投票
   发表时间:2009-12-26  
在隐藏之前留个爪
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics