This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [fortran, patch] Enable Hollerith constant and character array in format tag.


On Saturday 09 April 2005 22:18, Steve Kargl wrote:
> On Sat, Apr 09, 2005 at 09:56:31PM +0100, Paul Brook wrote:
> > On Saturday 09 April 2005 21:40, Steve Kargl wrote:
> > > int mpfr_set_str (mpfr_t X, char *S, int BASE, mp_rnd_t RND)
> > >
> > >   mpfr_set_str (x, 'dead', 16, GFC_RND_MODE);
> >
> > This won't work. The C equivalent of
> >  real :: a = 4hdead
> > is
> >  float a = *(float *)"dead";
>
> Are those signed or unsigned char?  Not that it matters.
>
> Then, Feng needs to convert 'dead' to the equilavent
> strings of zeros and ones, eg., '010010111....'
>
> char s[33];
> s = convert_to_binary('dead'); /* String of zeros and ones */
> mpfr_set_str (x, s, 2, GFC_RND_MODE);

This only works for integers (mpz). The code above will interpret the string 
as a binary integer, and x to that numerical value. What we want to set is 
the the binary representation of x.

> What happens with little and big endian systems?

I'm not sure. I suspect you get different answers.

IIUC hollerith constants date from before CHARACTER variables existed, and are 
typically used something like:

integer, parameter :: a(3) = 12hHello World!
open (unit=11, "file.txt", form="unformatted")
write (11) a

Paul


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]