博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
XDR-初探XDR对变长类型空间的管理。--log
阅读量:4046 次
发布时间:2019-05-24

本文共 2912 字,大约阅读时间需要 9 分钟。

XDR-初探XDR对变长类型空间的管理。--log

2014年4月8日22:35:00

.x文件

enum colors{ 	RED = 2, 	YELLOW = 3, 	BLUE = 5,	GREEN = 0x10};struct lww_int{	int m_nAge;	bool m_bMale;	string m_sName<255>;	colors m_ayColor[2];};union lww_union switch(colors clr){case RED:	int m_nAge;case YELLOW:	bool m_bMale;case BLUE:	string m_sName<255>;case GREEN:	colors m_ayColor[2];};
C程序:

#include 
#include
#include "lww.h"//int main()//{// printf("begin\n");//// FILE * pFile = fopen("lww.txt","wb");// XDR XDR;// xdrstdio_create(&XDR,pFile,XDR_ENCODE);//// colors aRED = RED;// colors aYELLOW = YELLOW;// colors aBLUE = BLUE;// colors aGREEN = GREEN;// lww_int aLwwInt;// aLwwInt.m_nAge = 28;// aLwwInt.m_bMale = TRUE;// aLwwInt.m_sName = (char *)"1234";// aLwwInt.m_ayColor[0] = GREEN;// aLwwInt.m_ayColor[1] = BLUE;// lww_union aLwwUnion;// aLwwUnion.clr = RED;// aLwwUnion.lww_union_u.m_nAge = 28 * 2;//// xdr_colors(&XDR,&aRED);// xdr_colors(&XDR,&aYELLOW);// xdr_colors(&XDR,&aBLUE);// xdr_colors(&XDR,&aGREEN);// xdr_lww_int(&XDR,&aLwwInt);// xdr_lww_union(&XDR,&aLwwUnion);//// xdr_destroy(&XDR);// fclose(pFile);//// printf("end\n");//// return 0;//}void printColor(colors aColor){ switch(aColor) { case RED: printf("红色\n"); break; case YELLOW: printf("黄色\n"); break; case BLUE: printf("蓝色\n"); break; case GREEN: printf("绿色\n"); break; default: printf("错误色\n"); break; } return;}void printBool(bool_t bPrint){ switch(bPrint) { case TRUE: printf("真\n"); break; case FALSE: printf("假\n"); break; default: printf("错误\n"); break; } return;}lww_int aLwwInt;void writeTLogFile(char * str){ FILE * pFileW = fopen("log.txt","a+"); if(NULL == pFileW) { return; } fprintf(pFileW,"\n%s",str); fclose(pFileW); return;}void writeBLogFile(char * str,int nCount){ FILE * pFileW = fopen("log.txt","ab+"); if(NULL == pFileW) { return; } fwrite(str,1,nCount,pFileW); fclose(pFileW); return;}int main(){ printf("begin\n"); writeTLogFile("加载前:"); writeBLogFile((char *)&aLwwInt,sizeof(aLwwInt)); FILE * pFile = fopen("lww.txt","rb"); XDR XDR; xdrstdio_create(&XDR,pFile,XDR_DECODE); colors aColor; char sName[255] = {0}; //lww_int aLwwInt; //aLwwInt.m_sName = sName; xdr_colors(&XDR,&aColor); printColor(aColor); xdr_colors(&XDR,&aColor); printColor(aColor); xdr_colors(&XDR,&aColor); printColor(aColor); xdr_colors(&XDR,&aColor); printColor(aColor); xdr_lww_int(&XDR,&aLwwInt); printf("%d\n",aLwwInt.m_nAge); printBool(aLwwInt.m_bMale); printf("%s\n",aLwwInt.m_sName); printColor(aLwwInt.m_ayColor[0]); printColor(aLwwInt.m_ayColor[1]); writeTLogFile("加载后:"); writeBLogFile((char *)&aLwwInt,sizeof(aLwwInt)); lww_union aLwwUnion; xdr_lww_union(&XDR,&aLwwUnion); if(RED == aLwwUnion.clr) { printf("%d\n",aLwwUnion.lww_union_u.m_nAge); } xdr_free((xdrproc_t)xdr_lww_int,(char *)&aLwwInt); writeTLogFile("释放后:"); writeBLogFile((char *)&aLwwInt,sizeof(aLwwInt)); xdr_destroy(&XDR); fclose(pFile); printf("end\n"); return 0;}

转载地址:http://knwci.baihongyu.com/

你可能感兴趣的文章
一个简单的TabLayout的使用
查看>>
ReactNative使用Redux例子
查看>>
Promise的基本使用
查看>>
coursesa课程 Python 3 programming 统计文件有多少单词
查看>>
coursesa课程 Python 3 programming 输出每一行句子的第三个单词
查看>>
Returning a value from a function
查看>>
coursesa课程 Python 3 programming Functions can call other functions 函数调用另一个函数
查看>>
coursesa课程 Python 3 programming The while Statement
查看>>
course_2_assessment_6
查看>>
coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题
查看>>
coursesa课程 Python 3 programming course_2_assessment_8 sorted练习题
查看>>
在unity中建立最小的shader(Minimal Shader)
查看>>
1.3 Debugging of Shaders (调试着色器)
查看>>
关于phpcms中模块_tag.class.php中的pc_tag()方法的含义
查看>>
vsftp 配置具有匿名登录也有系统用户登录,系统用户有管理权限,匿名只有下载权限。
查看>>
linux安装usb wifi接收器
查看>>
多线程使用随机函数需要注意的一点
查看>>
getpeername,getsockname
查看>>
让我做你的下一行Code
查看>>
浅析:setsockopt()改善程序的健壮性
查看>>