Subject: XDR and double data type
To: None <current-users@NetBSD.ORG>
From: Kent Vander Velden <graphix@iastate.edu>
List: current-users
Date: 06/05/1995 02:22:14
A few months a go I sent a mail message about XDR not encoding
double's correctly. I assumed the problem was fixed and had forgotten
about it until I spent an hour this evening tracking down a bug that
lead me to rediscover that XDR does not handle doubles properly. I have
enclosed sample code to demonstrate this fact which seems to work fine
with OSF/1 v2.x and Ultrix 4.3 (in other words, I think the code is
"correct"). If I use the float data type the conversions seem to work
without fault. The architecture that I have this problem on is the i386
architecture. I will not bore you with my whining of how badly I need
this to work...
Thanks.
---
#include <stdio.h>
#include <stdlib.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
int
main(void) {
double x=3.14159;
double y=0.0;
char *xdr_buffer=NULL;
XDR xdrs;
int nbytes=1024; /*sizeof(double);*/
xdr_buffer = (char*)malloc(nbytes);
xdrmem_create(&xdrs, xdr_buffer, nbytes, XDR_ENCODE);
xdr_double(&xdrs, &x);
xdr_destroy(&xdrs);
xdrmem_create(&xdrs, xdr_buffer, nbytes, XDR_DECODE);
xdr_double(&xdrs, &y);
xdr_destroy(&xdrs);
free(xdr_buffer);
printf("before encoding=%f\nafter encoding=%f\n", x, y);
return 0;
}
---
---
Kent Vander Velden
graphix@iastate.edu