dasomoli
1. About DasomOLI ¶
2. ³»°¡ ¾²°Å³ª °íÄ¡´Â ±Û ¶
4. Àǹ®ÀÇ ÄÚµå ¶ÀÌ°Ô ¿Ö Àǹ®ÀÇ ÄÚµåÁö?;;
#include <stdio.h>
#pragma pack(push, 1)
typedef struct Test1__t {
struct {
unsigned char Status;
unsigned char Reserved;
unsigned long Value;
} Sensor[5];
} Test1_t;
#pragma pack(pop)
#pragma pack(push, 2)
typedef struct Test2__t {
struct {
unsigned char Status;
unsigned float Value;
} Sensor[5];
} Test2_t;
#pragma pack(pop)
int main(void)
{
Test1_t Data1;
Test2_t *pData;
unsigned char Buffer[1000];
float *pf;
int i = 0;
Data1.Sensor[0].Status = 0;
pf = (float*)&(Data1.Sensor[0].Value); *pf = 30.6;
printf("[%d] pf : %f\n", i++, *pf);
Data1.Sensor[1].Status = 0;
pf = (float*)&(Data1.Sensor[1].Value); *pf = 27.0;
printf("[%d] pf : %f\n", i++, *pf);
Data1.Sensor[2].Status = 0;
pf = (float*)&(Data1.Sensor[2].Value); *pf = 1012.9;
printf("[%d] pf : %f\n", i++, *pf);
Data1.Sensor[3].Status = 0;
pf = (float*)&(Data1.Sensor[3].Value); *pf = 0.0;
printf("[%d] pf : %f\n", i++, *pf);
Data1.Sensor[4].Status = 0;
pf = (float*)&(Data1.Sensor[4].Value); *pf = 17.3;
printf("[%d] pf : %f\n", i++, *pf);
for(i = 0; i < sizeof(Test1_t); i++)
{
Buffer[i] = ((unsigned char*)&Data1)[i];
}
pData = (Test2_t*)&(Buffer[0]);
printf("Buffer ¿¡ ´ã°í Æ÷ÀÎÅÍ·Î Á¢±Ù\n");
for(i = 0; i < 5; i++)
{
printf("[%d] %f\n", i, pData->Sensor[i].Value);
}
pData = (Test2_t*)&Data1;
printf("±×³É Æ÷ÀÎÅÍ·Î Á¢±Ù\n");
for(i = 0; i < 5; i++)
{
printf("[%d] %f\n", i, pData->Sensor[i].Value);
}
return 0;
}
|
It is Fortune, not wisdom that rules man's life. |