comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Converting Byte Arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Converting Byte Arrays [message #10176 is a reply to message #10049] Wed, 08 October 1997 00:00 Go to previous message
davis is currently offline  davis
Messages: 15
Registered: March 1995
Junior Member
On Mon, 06 Oct 1997 16:54:55 -0500, Liam Gumley <liam.gumley@ssec.wisc.edu>
wrote:
> One way to read a data file with mixed variable types (integers, floats) is by
> using an anonymous structure, e.g.
>
> record = { var1:0, var2:0L, var3:0.0 }
> openr, lun, file, /get_lun
> readu, lun, record
> free_lun, lun
> help, record.var1, record.var2, record.var3

This is not really portable because you need to know how the structure
and data are padded. For example, consider the C code:

#include <stdio.h>
typedef struct
{
short s;
long l;
}
Short_Long_Type;

int main (int argc, char **argv)
{
Short_Long_Type sl;
FILE *fp;

sl.s = 1234;
sl.l = 2147483647;

fp = fopen ("sl.dat", "wb");
fwrite ((char *) &sl, sizeof (Short_Long_Type), 1, fp);
fclose (fp);
return 0;
}

In general, the SIZE of data file that this program produces will
vary. Under Linux, it produces an 8 byte file, whereas under DOS the
resulting file is 6 bytes. If you want portable datafiles, never
directly write out the structures.

--John
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: compiling into function
Next Topic: Re: programming languages vote - results

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:25:21 PDT 2025

Total time taken to generate the page: 0.00401 seconds