This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [fortran, patch] Enable Hollerith constant and character array in format tag.
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: Steven Bosscher <stevenb at suse dot de>
- Cc: fortran at gcc dot gnu dot org, Feng Wang <wf_cs at yahoo dot com>, gcc-patches at gcc dot gnu dot org
- Date: Mon, 28 Mar 2005 15:52:52 -0800
- Subject: Re: [fortran, patch] Enable Hollerith constant and character array in format tag.
- References: <20050328141734.25430.qmail@web15602.mail.cnb.yahoo.com> <200503290134.40610.stevenb@suse.de>
On Tue, Mar 29, 2005 at 01:34:40AM +0200, Steven Bosscher wrote:
> On Monday 28 March 2005 16:17, Feng Wang wrote:
> > * arith.c (gfc_hollerith2int, gfc_hollerith2real,
> > gfc_hollerith2complex, gfc_hollerith2character): New functions.
>
> All of these look wrong to me. If I understand Holleriths correctly,
> their value is a bitwise copy of the string to the target format of
> whatever they're supposed to represent. But you are copying the string
> value of the Holleriths into an mpz_t, a single mpfr_t, or a pair of
> mpfr_t. That can't be right.
>
> Gr.
> Steven
I don't think he's storing the Hollerith in the integer's mpz_t,
the real's single mpfr_t, or complex's 2 mpfr_t. A closer
look shows that he is storing the KIND number of bytes in the
result's string field.
gfc_expr *
gfc_hollerith2int (gfc_expr * src, int kind)
{
gfc_expr *result;
int len;
len = src->value.character.length;
result = gfc_get_expr ();
The next few lines set the type and kind for integer, but
also sets the from_H bit to true.
result->expr_type = EXPR_CONSTANT;
result->ts.type = BT_INTEGER;
result->ts.kind = kind;
result->where = src->where;
result->from_H = 1;
This if () now determines the total number of bytes to use
if (len > kind)
{
gfc_warning ();
len = kind;
}
Here he is saving the KIND number of bytes into result's
value.character.string field. In essences, he isn't doing
a conversion.
result->value.character.string = gfc_getmem (len + 1);
memcpy (result->value.character.string, src->value.character.string, len);
result->value.character.string[len] = '\0';
result->value.character.length = len;
return result;
}
--
Steve