dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]stdio in pnetC ... some questions


From: Rhys Weatherley
Subject: Re: [DotGNU]stdio in pnetC ... some questions
Date: Mon, 26 Aug 2002 08:46:27 +1000

Gopal V wrote:

> I found out that there is no FILE * or fread/fwrite/fopen functions
> in pnetC (which should be easily remediable :-)

Pretty soon.  I need to fix some linker bugs and the
global initializer problem, and then I should be able
to import glibc's stdio implementation en masse.

> The question I was thinking about was the endianess of the data read
> (using BinaryReader I presume)..
> 
> Using gcc I have the following behavior
> 
> fread(&i,1,sizeof(int),fp);
> printf("%08X",i);
> 
> on a file containing (java .class magic number)
> 
> 0xCA 0xFE 0xBA 0xBE
> 
> I get the following output
> 
> BEBAFECA

You'll only get that on a little-endian machine.  Big-endian
will give you CAFEBABE.  PDP-endian will give you BABECAFE.
So, your code isn't portable at the momemt.

> Will pnetC emulate that ? (and leave me to flip the bits ?)

It is up to the programmer to deal with endian-ness issues.
I suggest creating functions called "read_int", "read_short",
"read_float", etc that read in a value of the correct size
and then convert from big endian to host order.

This is the safest, and most portable, way to handle endian
problems.  Assuming anything about host order, even under gcc,
is fraught with danger.

Cheers,

Rhys.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]