In the following code, I m trying to copy struct element to array...
Code:
#include<iostream>
#include<stdint.h>
#include<string>
using namespace std;
struct test
{
struct header
{
int a;
int b;
};
uint8_t c;
uint8_t d;
uint8_t e;
uint32_t f;
};
struct test2
{
uint8_t n;
uint8_t m;
uint8_t p;
};
int main()
{
test headd;
test2 data;
uint8_t* d;
int x, y,i;
x= sizeof(test);
y= sizeof(test::header);
i= sizeof(data);
x=x+y+i;
d = new uint8_t[x+10];
cout<<"x ="<<x<<endl;
/** Assign **/
headd.c = 4;
headd.d = 5;
data.n=8;
data.m=7;
data.p=9;
/** copy 2 elements of struct 'headd' and struct 'data' on to memory block pointed by 'd' **/
memcpy(d,&headd.c,8);
cout<<"d="<<*d<<endl;
cout<<"d2="<<*(d+1)<<endl;
memcpy(d+8,&data, 8);
cout<<"d="<<*d<<endl;
cout<<"d2="<<*(d+2)<<endl;
return 0;
}
x =19
d=
d2=
d=
d2=
I ve replaced uint8_t and uint32_t by datatype 'int' and it works well... i can display contents of 'd'
but not for uint8_t and uint32_t .
Please suggest me how can i check whether data successfully copied to destination?
Thank You

